node-zone

minimal Zone implementation for Node

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
node-zone
0.4.05 years ago7 years agoMinified + gzip package size for node-zone in KB

Readme

node-zone Build Status
minimal Zone implementation for Node

This implementation is based on the experimental AsyncWrap API, but it seems to work fine.
Work with any asynchronous tasks (IO, timers, promises, external modules, …).

Install

Installation of the npm package:
> npm install --save node-zone

Usage

import { current } from 'node-zone'

// a zone has a name, a parent, and data
console.log(
  current.name,   // "<root>"
  current.parent, // null
  current.data    // { __proto__: null }
)

// create a new child zone
const myZone = current.fork('my zone')

console.log(
  myZone.name,   // "my zone"
  myZone.parent, // current
  myZone.data    // { __proto__: current.data }
)

// run some code in it
myZone.run(() => {
  console.log(current.name) // "my zone"

  // zone is preserved in async functions
  process.nextTick(() => {
    console.log(current.name) // "my zone"
  })
})

console.log(current.name) // "<root>"

Note: There is an issue with Node cluster module, which prevents handlers created in workers to properly access the current zone, Zone.current will be the root zone instead.

Development

# Install dependencies
> yarn

# Run the tests
> yarn test

# Continuously compile
> yarn dev

# Continuously run the tests
> yarn dev-test

# Build for production (automatically called by npm install)
> yarn build

Contributions

Contributions are very welcomed, either on the documentation or on the code.
You may:
you've encountered;
  • fork and create a pull request.

License

ISC © Julien Fontanet