Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    stream-recreatepublic

    Recreate stream in case of error

    To get started, install stream-recreate package via npm::

    % npm install stream-recreate
    

    The basic usage example is as follows::

    var recreate = require('stream-recreate'),
        websocket = require('websocket-stream');
    
    var socket = recreate(function() {
      return websocket('ws://localhost:3000');
    });
    
    socket.write('data');
    

    Returned socket stream will recreate underlying websocket stream if end or error event is occurred. It uses backoff module to control the interval between attempts to recreate a stream.

    To shutdown cleanly call socket.end().

    Note that we can call socket.write() right after the creation even if underlying websocket() stream isn't open yet — stream-recreate returns another stream which buffers writes and drains buffers on open of an underlying stream.

    Keywords

    none

    install

    npm i stream-recreate

    Downloadsweekly downloads

    9

    version

    1.0.0

    license

    none

    repository

    githubgithub

    last publish

    collaborators

    • avatar