tmfy
Timeouts for promises and promisified functions
Pronunciation: timeify, Thai-Me-Fy
Quick Start
npm install tmfy
var tmfy = ; var lib = { // need 200ms to send return { }; } { // need 20000ms to send return { }; }; tmfy; lib // timeout after 1000ms ; lib // timeout after 1000ms ;
API
timeout(mil, promise)
timeout(mil, handler, promise)
Returns a Promise.
- Resolves if
promise
is resolved beforemil
ms timeout.promise
result is passed. - Rejects if
promise
is rejected beforemil
ms timeout.promise
error is passed. - Rejects with
new Error('TIMEOUT')
ifmil
ms timeout beforepromise
is resolved or rejected.
If handler
is set and have emit()
, error
event will be emitted on timeout with new Error('TIMEOUT')
.
timeify(func)
func
must returns a Promise.
Returns a wrapped function around func
which accepts mil
as a first argument:
var funcTimeout = tmfy;; // runs func(...) with 1000ms timeout
A wrapped function returns a Promise. Same logic as for timeout()
applies.
If this
is set and have emit()
, error
event will be emitted on timeout with new Error('TIMEOUT')
.
timeifyAll(obj)
Extends obj
with timeified versions of all functions. Adds 'Timeout' suffix to wrapped functions.
var obj = { return Promise; };tmfy;obj
License
Copyright (c) 2016 AfterShip
Licensed under the MIT license.