1.0.2 • Published 2 years ago
nv-facutil-simple-signal v1.0.2
nv-facutil-simple-signal
- simple promise signal
install
- npm install nv-facutil-simple-signal
usage
const {pool,Pool} = require("nv-facutil-simple-signal")
example
async function tst(sig) {
console.log('wait...',new Date())
await sig;
console.log('finished:',new Date())
}
> pool.add('A')
Signal [Promise] {
<pending>,
name: 'A',
history: [],
max_history_size: 10,
tmout: undefined,
tmout_msg: 'tmout',
[Symbol(async_id_symbol)]: 233,
[Symbol(trigger_async_id_symbol)]: 5,
[Symbol(destroyed)]: { destroyed: false }
}
tst(pool.A)
> tst(sig)
wait... 2021-11-29T08:51:39.528Z
Promise { <pending> }
>
> pool.A.send({succ:100})
undefined
> finished: 2021-11-29T08:52:42.522Z
> pool.A
Signal [Promise] {
{ succ: 100 },
name: 'A',
history: [ { succ: 100 } ],
max_history_size: 10,
tmout: undefined,
tmout_msg: 'tmout'
}
> pool.A.respawn()
undefined
> pool.A
Signal [Promise] {
<pending>,//---------------------------->
name: 'A',
history: [ { succ: 100 } ],
max_history_size: 10,
tmout: undefined,
tmout_msg: 'tmout'
}
>
> tst(pool.A)
wait... 2021-11-29T08:57:19.117Z
Promise { <pending> }
>
> pool.A.send({fail:250})
undefined
> finished: 2021-11-29T08:57:33.535Z
> pool.A
Signal [Promise] {
{ fail: 250 },
name: 'A',
history: [ { succ: 100 }, { fail: 250 } ],
max_history_size: 10,
tmout: undefined,
tmout_msg: 'tmout'
}
>
APIS
signal
- send(msg)
- respawn(tmout=this.tmout,tmout_msg=this.tmout_msg,max_history_size=this.max_history_size)
- send_and_respawn(msg,tmout=this.tmout,tmout_msg=this.tmout_msg,max_history_size=this.max_history_size)
pool
- add(name):Signal
LICENSE
- ISC