Skip to content

Wrap an async function to time out after a specified interval

License

Notifications You must be signed in to change notification settings

bendrucker/fn-timeout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fn-timeout Build Status

Wrap an async function to time out after a specified interval

Install

$ npm install --save fn-timeout

Usage

var timeout = require('fn-timeout')

var fn = timeout(function (err, data) {
  //=> receives an err if not called within a second  
}, 1000)

API

timeout(callback, delay, [error]) -> function

Returns the original callback

callback

Required
Type: function

The callback to time out.

delay

Required
Type: number

A time limit in milliseconds.

error

Type: object
Default: {message: 'Operation timed out after {delay} ms'}

An object with error. The following template values can be used in your custom message:

  • delay: the specified delay for the timeout

You can also add additional values of your own. They will be appended to the err object and available for templating in the message.

License

MIT © Ben Drucker

About

Wrap an async function to time out after a specified interval

Resources

License

Stars

Watchers

Forks

Packages