2016-07-07 1 views
5

Diffusion JS APIのコード例をいくつか使っていますが、再接続時の例は分かりません。 reconnectionStrategyのstartabortパラメータは何ですか? 説明できない引数がJSクライアントに渡されました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

+0

ところで、reconnectionStrategyを返される関数と同じにすることができます。なぜそれがそれであるかを説明する独自のローカル変数を以前に含んでいた可能性があります。 –

答えて

5

これらの2つの引数がreconnectabortin the manualとして記述されているから撮影、両方が使用するように置くことができる機能があります。

  • start/reconnect - 再接続の試行を開始します。クライアントに別の接続を試みるように指示します。

  • abort - 再接続を中止するために呼び出すことができます。この場合、クライアントが終了します。それ以上の試みが役に立たない、あるいはそうでなければ望ましくないと思われる場合は、これを呼んでください。我々は、例は60年代の最大値まで指数関数的に(100ミリ秒、200ミリ秒、400msの、等)を増加させる待つ間の再接続を試みることがわかり、この理解により

。再接続の試みが失敗した場合、再接続戦略機能が再度呼び出されます。

4

機能もラップする必要はありません。

var reconnectionStrategy = 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);}; 

は、同じようにうまくやるとあまり混乱するでしょう。

関連する問題