json-rpc-engine
Advanced tools
Comparing version 3.6.1 to 3.6.2
{ | ||
"name": "json-rpc-engine", | ||
"version": "3.6.1", | ||
"version": "3.6.2", | ||
"description": "a tool for processing JSON RPC", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -8,9 +8,13 @@ const promiseToCallback = require('promise-to-callback') | ||
return (req, res, next, end) => { | ||
let nextHandlerOnDone = null | ||
let nextDonePromise = null | ||
const finishedPromise = asyncMiddleware(req, res, getNextPromise) | ||
promiseToCallback(finishedPromise)((err) => { | ||
// async middleware ended | ||
if (nextHandlerOnDone) { | ||
if (nextDonePromise) { | ||
console.log('detected next was called') | ||
// next handler was called - complete nextHandler | ||
nextHandlerOnDone(err) | ||
promiseToCallback(nextDonePromise)((nextErr, nextHandlerSignalDone) => { | ||
if (nextErr) return done(nextErr) | ||
nextHandlerSignalDone(err) | ||
}) | ||
} else { | ||
@@ -22,11 +26,14 @@ // next handler was not called - complete middleware | ||
function getNextPromise() { | ||
async function getNextPromise() { | ||
nextDonePromise = getNextDoneCallback() | ||
await nextDonePromise | ||
return undefined | ||
} | ||
function getNextDoneCallback() { | ||
return new Promise((resolve) => { | ||
next((cb) => { | ||
nextHandlerOnDone = cb | ||
resolve() | ||
}) | ||
next((cb) => resolve(cb)) | ||
}) | ||
} | ||
} | ||
} | ||
} |
@@ -93,2 +93,22 @@ /* eslint-env mocha */ | ||
}) | ||
it('doesnt await next', function (done) { | ||
let engine = new RpcEngine() | ||
engine.push(createAsyncMiddleware(async (req, res, next) => { | ||
next() | ||
})) | ||
engine.push(function (req, res, next, end) { | ||
res.result = 1234 | ||
end() | ||
}) | ||
let payload = { id: 1, jsonrpc: '2.0', method: 'hello' } | ||
engine.handle(payload, function (err, res) { | ||
assert.ifError(err, 'has err') | ||
done() | ||
}) | ||
}) | ||
}) |
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
21600
581