# continuation-local-variable

> Variables scoped by a chain of asynchrounous calls

Latest version **1.0.4** (published 2018-02-25) · 0 weekly downloads

## Install

```sh
npm install continuation-local-variable
pnpm add continuation-local-variable
yarn add continuation-local-variable
bun add continuation-local-variable
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-02-25 |
| First published | 2018-02-25 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Marcos Pernambuco Motta |
| Maintainers | mpernambuco |
| Keywords | threading, continuation, context, local, storage, logging |

## Links

- npm: https://www.npmjs.com/package/continuation-local-variable
- Repository: https://github.com/mpernambuco/continuation-local-variable
- Homepage: https://github.com/mpernambuco/continuation-local-variable#readme
- Issues: https://github.com/mpernambuco/continuation-local-variable/issues
- npm.io page: https://npm.io/package/continuation-local-variable

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.4 (latest) — 2018-02-25
- 1.0.3 — 2018-02-25
- 1.0.2 — 2018-02-25
- 1.0.1 — 2018-02-25
- 1.0.0 — 2018-02-25

## README

# continuation-local-variable
Variables scoped by a chain of asynchrounous calls

## How it works

```js
    const Variable = require('continuation-local-variable');

    const User = Variable.create('user');
    User.set("Moe");

    setTimeout(function() {
      print(Variable.find('user').value());  // prints 'Moe'
    }, 1000);

    // User name will be 'Larry' for the chain of async operations
    // starting with `setTimeout`
    User.set("Larry"); sets
    setTimeout(function() {
      print(Variable.find('user').value());  // prints 'Larry'
      // http request
      axios.get('http://www.github.com').then(() => {
        print(Variable.find('user').value());  // still prints 'Larry'
      })
    }, 500);

    // User name is 'Curly' for the async chain starting with the next `setTimeout`
    User.set("Curly");
    setTimeout(function() {
      print(Variable.find('user').value());  // prints 'Curly'
      process.nextTick(() => {
        print(Variable.find('user').value());  // prints 'Curly'
      });
    }, 500);

```

## Requirements

NodeJS 8.9 or above

## API  Reference

### Variable.create(variableName)
Creates a new async scoped variable

### Variable.find(variableName)
Finds an existing variable

### Variable.set(value)
Sets the value of the variable.
This value will hold for the duration of the next asynchronous call chain.

### Variable.get()
Returns the value of this variable.

---
_Source: https://npm.io/package/continuation-local-variable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
