UNPKG

rest-api-starter

Version:
36 lines (32 loc) 851 B
/** * Created by svinci on 1/12/17. */ 'use strict'; const domain = require('domain'); const createStore = (cb) => { domain.create().run(function() { cb(); }); }; module.exports = { 'create': createStore, 'destroy': () => { delete process.domain; }, 'putValue': (key, value) => { if (process.domain) { process.domain[key] = value; } else { throw Error('You need to initialize a store for this transaction, before adding values to it.'); } }, 'getValue': (key, defaultValue) => { if (process.domain) { return process.domain[key]; } if (defaultValue) { return defaultValue; } throw Error('You need to initialize a store for this transaction, before retrieving values from it.'); } };