rest-api-starter
Version:
Rest API starter kit.
36 lines (32 loc) • 851 B
JavaScript
/**
* Created by svinci on 1/12/17.
*/
;
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.');
}
};