fast-future
A really fast way to run a callback in the future
Last updated 8 years ago by kesla .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install fast-future 
SYNC missed versions from official npm registry.

fast-futurebuild status

A really fast way to run a callback in the future

NPM

NPM

Installation

npm install fast-future

What? How does is work?

Since node.js v0.10.x the semantics of process.nextTick changed (see docs). To get the old behaviour one can use setImmediate instead.

The good part about process.nextTick is that it's really really fast. The bad part is that event loop can be starved and if run for to long time it'll eventually die with a RangeError: Maximum call stack size exceeded.

What's good about setImmediate is that it won't starve the event loop. However, it's a bit slower than process.nextTick.

fast-future uses the best from the both worlds - the callback will most of the times be called in a process.nextTick, but once in a while it'll get run in a setImmediate - so you'll get crazy performance, and the event loop won't get starved or crash or something sad like that.

For me running the benchmarks show the following result

# setImmediate
setImmediate: 2317ms
# fastFuture
fastFuture: 96ms

For node v0.8.x it'll fallback to using process.nextTick

Example

var fastFuture = require('./fast-future')()

fastFuture(function () {
  console.log('this is being run in the future')
})

Kudos

Thanks @mafintosh for suggesting this!

Licence

Copyright (c) 2014 David Björklund

This software is released under the MIT license:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Current Tags

  • 1.0.2                                ...           latest (8 years ago)

3 Versions

  • 1.0.2                                ...           8 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |