fast-future

WebJar for fast-future

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

fast-future
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

fast-future
WebJar for fast-future
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/kesla/fast-future

Download fast-future

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/fast-future/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>fast-future</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/fast-future/
implementation 'org.webjars.npm:fast-future:1.0.2'
// https://jarcasting.com/artifacts/org.webjars.npm/fast-future/
implementation ("org.webjars.npm:fast-future:1.0.2")
'org.webjars.npm:fast-future:jar:1.0.2'
<dependency org="org.webjars.npm" name="fast-future" rev="1.0.2">
  <artifact name="fast-future" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='fast-future', version='1.0.2')
)
libraryDependencies += "org.webjars.npm" % "fast-future" % "1.0.2"
[org.webjars.npm/fast-future "1.0.2"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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.

Versions

Version
1.0.2