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
ebc1e7664e
commit
716c45f4bf
8
index.js
8
index.js
@ -207,16 +207,16 @@ class Fuse extends Nanoresource {
|
|||||||
return handlers
|
return handlers
|
||||||
|
|
||||||
function makeHandler (name, op, defaults, nativeSignal) {
|
function makeHandler (name, op, defaults, nativeSignal) {
|
||||||
return function () {
|
return function (nativeHandler, opCode, ...args) {
|
||||||
const boundSignal = signal.bind(null, arguments[0])
|
const boundSignal = signal.bind(null, nativeHandler)
|
||||||
const funcName = `_op_${name}`
|
const funcName = `_op_${name}`
|
||||||
if (!self[funcName] || !self._implemented.has(op)) return boundSignal(-1, ...defaults)
|
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) {
|
function signal (nativeHandler, err, ...args) {
|
||||||
var arr = [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)
|
return process.nextTick(nativeSignal, ...arr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user