timeout-callback
callback function wrapper with timeout functionality
Last updated a year ago by jakub.knejzlik .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install timeout-callback 
SYNC missed versions from official npm registry.

When working with socket.io emitted message with callback, if the socket disconnect before answering (or doesn't answer at all) the callback function hangs up forever. In these situations you need to timeout this callback.

This wrapper makes this task easy. Just do:

var timeoutCallback = require('timeout-callback');

socket.emit('message-expecting-answer',timeoutCallback(function(err,arg1,arg2){
	console.log('this log is always displayed!');
}));

By default timeout is set to 10 seconds, you can change this interval by specifying timeout as first argument (in milliseconds)

timeoutCallback(60*1000,myCallbackFunction);

If the timeout is reached, the callback is called with error new Error('callback timeout') as the first argument.

Current Tags

  • 2.0.2                                ...           latest (a year ago)

8 Versions

  • 2.0.2                                ...           a year ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.0                                ...           4 years ago
  • 0.0.4                                ...           5 years ago
  • 0.0.3                                ...           5 years ago
  • 0.0.2                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 1
This Week 9
This Month 13
Last Day 0
Last Week 1
Last Month 8
Dependencies (1)
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |