Skip to content

DmitryMyadzelets/watchdog-callback

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

watchdog-callback

npm install watchdog-callback --save

I use it for socket.io. In the example below the callback may never be called:

socket.emit('any-event', function (err, data) {
    if (err) {
        return console.error(err);
    }
    // have fun with data
});

To make sure it will, use the watchdog:

var wdc = require('watchdog-callback');

socket.emit('any-event', wdc(function (tout, err, data) {
    if (tout) {
        return console.error(tout);
    }
    if (err) {
        return console.error(err);
    }
    // have fun with data
}));

The default timeout is 5000 milliseconds. You can change it:

// 1 second timeout
socket.emit('any-event', wdc(1000, callback));

The credits should be given to Jakub Knejzlík, the author of timeout-callback. His module just didn't worked as I expected, at that time.

About

Makes sure the callaback will be called

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published