1.0.5 • Published 4 years ago

async-namespace v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

async-namespace

import Namespace from 'async-namespace';

const ctx = new Namespace('name');
// or
const ctx = Namespace.for('name');

simple example:

const log = (...args) => console.log(ctx.get('userid'), args);

server.use(() => {
  // some auth logic..
  ctx.set('user', new User({...}));
  ctx.set('userid', 123456789123456789);

  log('auth finished'); // => 123456789123456789 ['auth finished']
});

server.get('/cpu/work', event => {
  log('very big cpu work!! :)'); // => 123456789123456789 ['very big cpu work!! :)']
});
const ctx = new Namespace(':)');
const ctx = Namespace.for(':)');

// safe methods
ctx.get(key); // Map.prototype.get
ctx.set(key, value); // Map.prototype.set (returns value)

ctx.keys(); // Map.prototype.keys
ctx.clear(); // Map.prototype.clear
ctx.values(); // Map.prototype.values
ctx.entries(); // Map.prototype.entries
ctx.delete(key); // Map.prototype.delete

// unsafe underlaying map access
ctx.map // => Map | undefined


ctx.destroy() // destroys the async hook and all maps
1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago