gpt4 book ai didi

push-diffusion - 无法解释的参数传递给 JS 客户端重新连接策略

转载 作者:行者123 更新时间:2023-12-04 17:44:54 24 4
gpt4 key购买 nike

我正在研究 Diffusion JS API 的一些代码示例,但我不了解重新连接的示例。什么是startabort reconnectionStrategy 的参数?

// Create a reconnection strategy that applies an exponential back-off
var reconnectionStrategy = (function() {
return function(start, abort) {
var wait = Math.min(Math.pow(2, attempts++) * 100, maximumAttemptInterval);

// Wait and then try to start the reconnection attempt
setTimeout(start, wait);
};
})();

// Connect to the server.
diffusion.connect({
host : 'diffusion.example.com',
port : 443,
secure : true,
principal : 'control',
credentials : 'password',
reconnect : {
timeout : maximumTimeoutDuration,
strategy : reconnectionStrategy
}
}).then(function(session) {

取自 https://github.com/pushtechnology/diffusion-examples/blob/master/js/examples/reconnect.js

最佳答案

这两个参数被描述为 reconnectabort in the manual ,两者都是可以投入使用的功能。

  • start/reconnect - 将启动重新连接尝试。指示客户端尝试另一个连接。
  • abort - 可能会被调用以中止重新连接,在这种情况下客户端将被关闭。如果您认为进一步的尝试将徒劳无功或在其他方面不受欢迎,请调用此方法。

  • 通过这种理解,我们看到该示例尝试在以指数方式(100 毫秒、200 毫秒、400 毫秒等)增加到最多 60 秒的等待之间重新连接。如果重新连接尝试失败,则再次调用重新连接策略函数。

    关于push-diffusion - 无法解释的参数传递给 JS 客户端重新连接策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38246746/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com