mirror of
https://github.com/fuse-friends/fuse-native
synced 2024-10-27 18:34:01 +00:00
more timeout logic
This commit is contained in:
parent
38a4a52231
commit
9d0892abdd
10
index.js
10
index.js
@ -203,7 +203,6 @@ class Fuse extends Nanoresource {
|
|||||||
_makeHandlerArray () {
|
_makeHandlerArray () {
|
||||||
const self = this
|
const self = this
|
||||||
const handlers = new Array(OpcodesAndDefaults.size)
|
const handlers = new Array(OpcodesAndDefaults.size)
|
||||||
const to = this.timeout
|
|
||||||
|
|
||||||
for (const [name, { op, defaults }] of OpcodesAndDefaults) {
|
for (const [name, { op, defaults }] of OpcodesAndDefaults) {
|
||||||
const nativeSignal = binding[`fuse_native_signal_${name}`]
|
const nativeSignal = binding[`fuse_native_signal_${name}`]
|
||||||
@ -215,6 +214,13 @@ class Fuse extends Nanoresource {
|
|||||||
return handlers
|
return handlers
|
||||||
|
|
||||||
function makeHandler (name, op, defaults, nativeSignal) {
|
function makeHandler (name, op, defaults, nativeSignal) {
|
||||||
|
let to = self.timeout
|
||||||
|
if (typeof to === 'object' && to) {
|
||||||
|
const defaultTimeout = to.default || DEFAULT_TIMEOUT
|
||||||
|
to = to[name]
|
||||||
|
if (!to && to !== false) to = defaultTimeout
|
||||||
|
}
|
||||||
|
|
||||||
return function (nativeHandler, opCode, ...args) {
|
return function (nativeHandler, opCode, ...args) {
|
||||||
const sig = signal.bind(null, nativeHandler)
|
const sig = signal.bind(null, nativeHandler)
|
||||||
const boundSignal = to ? autoTimeout(sig) : sig
|
const boundSignal = to ? autoTimeout(sig) : sig
|
||||||
@ -231,7 +237,6 @@ class Fuse extends Nanoresource {
|
|||||||
}
|
}
|
||||||
return process.nextTick(nativeSignal, ...arr)
|
return process.nextTick(nativeSignal, ...arr)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function autoTimeout (cb) {
|
function autoTimeout (cb) {
|
||||||
let called = false
|
let called = false
|
||||||
@ -246,6 +251,7 @@ class Fuse extends Nanoresource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Static methods
|
// Static methods
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user