2.1.1 • Published 4 months ago

asyncctx v2.1.1

Weekly downloads
3,068
License
MIT
Repository
github
Last release
4 months ago

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

2.1.1

4 months ago

2.1.0

5 months ago

2.0.19

2 years ago

2.0.18

3 years ago

2.0.17

3 years ago

2.0.16

3 years ago

2.0.15

3 years ago

2.0.14

4 years ago

2.0.13

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

2.0.12

4 years ago

1.1.9

4 years ago

2.0.11

4 years ago

1.1.8

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

1.1.7

4 years ago

2.0.8

5 years ago

1.1.6

5 years ago

2.0.7

5 years ago

1.1.5

5 years ago

2.0.6

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

1.1.2

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

1.1.1

5 years ago

2.0.1

5 years ago

1.1.0

5 years ago

2.0.0

5 years ago

1.0.10

5 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago