mirror of
https://github.com/fuse-friends/fuse-native
synced 2024-10-27 18:34:01 +00:00
Better makeHandler
This commit is contained in:
parent
f6dcf4b680
commit
420da8ccbb
8
index.js
8
index.js
@ -207,16 +207,16 @@ class Fuse extends Nanoresource {
|
||||
return handlers
|
||||
|
||||
function makeHandler (name, op, defaults, nativeSignal) {
|
||||
return function () {
|
||||
const boundSignal = signal.bind(null, arguments[0])
|
||||
return function (nativeHandler, opCode, ...args) {
|
||||
const boundSignal = signal.bind(null, nativeHandler)
|
||||
const funcName = `_op_${name}`
|
||||
if (!self[funcName] || !self._implemented.has(op)) return boundSignal(-1, ...defaults)
|
||||
return self[funcName].apply(self, [boundSignal, ...[...arguments].slice(2)])
|
||||
return self[funcName].apply(self, [boundSignal, ...args])
|
||||
}
|
||||
|
||||
function signal (nativeHandler, err, ...args) {
|
||||
var arr = [nativeHandler, err, ...args]
|
||||
if (defaults && (!args || !args.length)) arr = arr.concat(defaults)
|
||||
if (defaults && (!args.length)) arr = arr.concat(defaults)
|
||||
return process.nextTick(nativeSignal, ...arr)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user