Socket
Book a DemoInstallSign in
Socket

async-state

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-state

Parse state across async callbacks

latest
Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
6
-60%
Maintainers
1
Weekly downloads
 
Created
Source

async-state

Parse state across async callbacks.

Build status js-standard-style

Installation

npm install async-state

Usage

var asyncState = require('async-state')()

asyncState.foo = 'foo'

setTimeout(function () {
  console.log(asyncState.foo) // => foo
}, 2000)

asyncState.foo = 'bar'

This also works between files. For a more complex example, see the example folder.

Gotchas

Only object references are copied across async bounderies. The content of the object is shared! I.e. the following will get you into trouble:

var asyncState = require('async-state')()

asyncState.obj = { foo: 'foo' }

setTimeout(function () {
  console.log(asyncState.obj.foo) // => bar
}, 2000)

// THIS IS BAD!
asyncState.obj.foo = 'bar'

To solve that issue, implement your own cloning logic:

var asyncState = require('async-state')()

asyncState.obj = { foo: 'foo' }

setTimeout(function () {
  console.log(asyncState.obj.foo) // => foo
}, 2000)

// THIS IS GOOD :)
asyncState.obj = { foo: 'bar' }

Credits

Thanks to Andreas Madsen for pointing me towards the async_wrap API.

License

MIT

Keywords

async

FAQs

Package last updated on 22 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts