node-fibers-synchronize-helper
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "node-fibers-synchronize-helper", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "helper for synchronize promise and callback", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# node-fibers-synchronize-helper | ||
# node-fibers-synchronize-helper | ||
This helper uses synchronize module (https://www.npmjs.com/package/synchronize) and helps to manage promises and callbacks, you will be able to synch code and catch exceptions | ||
Promise management: | ||
``` | ||
var synchProm = require('node-fibers-synchronize-helper') | ||
var testSynch = function () { | ||
try{ | ||
//promise function call | ||
var db = synchProm.executePromiseFiberFn(MongoClient, MongoClient.connect, url) | ||
//get synch object and call promise function | ||
var dbProm = synchProm.getSynchPromiseObj(db); | ||
var stats = dbProm.executePromiseFiber(db.stats) | ||
//cursor.toArray promise version | ||
var cursor = collection_test.find({}); | ||
var resProm = synchProm.executePromiseFiberFn(cursor, cursor.toArray) | ||
}catch(e){ | ||
console.log(e) | ||
} | ||
} | ||
synchProm.executeSynch(testSynch, function (err, res) { | ||
if (err) | ||
console.log("err", err) | ||
else | ||
console.log("OK:", JSON.stringify(res, null, 4)) | ||
}) | ||
``` | ||
Callback management: | ||
``` | ||
var synchProm = require('node-fibers-synchronize-helper') | ||
var testSynch = function () { | ||
try{ | ||
//cursor.toArray callback version | ||
cursor = collection_test.find({}); | ||
var resCb = synchProm.executeFiberFn(cursor, cursor.toArray) | ||
assert.notEqual(null, resCb); | ||
//callback with param | ||
resCb = synchProm.executeFiberFn(cursor, cursor.count, true, { | ||
skip: 1 | ||
}) | ||
//multiparam result callback | ||
var resMultiCb = synchProm.executeFiberFnMultiParamCb(this, multiParamCB, ['res1', 'res2'], "a", "b", "c") | ||
}catch(e){ | ||
console.log(e) | ||
} | ||
} | ||
synchProm.executeSynch(testSynch, function (err, res) { | ||
if (err) | ||
console.log("err", err) | ||
else | ||
console.log("OK:", JSON.stringify(res, null, 4)) | ||
}) | ||
``` | ||
@@ -7,3 +7,3 @@ //TEST | ||
var synchProm = require('./synchProm') | ||
var synchProm = require('node-fibers-synchronize-helper') | ||
@@ -68,3 +68,9 @@ | ||
console.log("cursor.count") | ||
resCb = synchProm.executeFiberFn(cursor, cursor.count, true, { | ||
skip: 1 | ||
}) | ||
assert.notEqual(null, resCb); | ||
var resMultiCb = synchProm.executeFiberFnMultiParamCb(this, multiParamCB, ['res1', 'res2'], "a", "b", "c") | ||
@@ -71,0 +77,0 @@ console.log("res resMultiCb:", resMultiCb) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10724
222
85