Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asyncctx

Package Overview
Dependencies
Maintainers
0
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asyncctx

an asynchronous execution context for TypeScript/JavaScript

  • 2.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
797
decreased by-35.57%
Maintainers
0
Weekly downloads
 
Created
Source

npm version Build Workflow Coverage Status DeepScan grade Known Vulnerabilities

PRs Welcome License

node-async-context (asyncctx)

This module allows you to create an asynchronous execution context for JavaScript or TypeScript

NOTE: This module is based on async_hooks an experimental built-in node.js module introduced in v8.0.0

Deprecation

NOTE: This module is now deprecated in favour of AsyncLocalStorage which is available for nodejs >= 12

quick start using AsyncLocalStorage

class ContinuationLocalStorage<T> extends AsyncLocalStorage<T> {
  public getContext(): T | undefined {
    return this.getStore();
  }
  public setContext(value: T): T {
    this.enterWith(value);
    return value;
  }
}

Introduction

To give you an idea of how asyncctx is supposed to be used:

import { ContinuationLocalStorage } from 'asyncctx';

class MyLocalStorage {
  value: number;
}

let cls = new ContinuationLocalStorage<MyLocalStorage>();
cls.setRootContext({ value: 1 });

process.nextTick(() => {
  let curr1 = cls.getContext(); // value is 1
  cls.setContext({ value: 2 }); // value should be 2 in the current execution context and below
  process.nextTick(() => {
    let curr2 = cls.getContext(); // value is 2
    cls.setContext({ value: 3 }); // value should be 3 in the current execution context and below
    process.nextTick(() => {
      let curr3 = cls.getContext(); // value is 3
    });
  });
  process.nextTick(() => {
    let curr4 = cls.getContext(); // value is 2
  });
});

RELEASE NOTES

CHANGELOG

License

node-async-context (asyncctx) is licensed under the MIT License: LICENSE

Keywords

FAQs

Package last updated on 26 Oct 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc