Suspendify wrapper for Pear threads. Handles Bare suspend/resume/wakeup events in the child, with optional store and swarm hooks.
npm install pear-suspension
Parent
const thread = new Bare.Thread('./worker.js')
thread.suspend(5000)
thread.resume()
Child (worker.js)
const PearSuspension = require('pear-suspension')
const sus = new PearSuspension({
store,
swarm,
async pollLinger() {
return msLeft
},
async suspend() {},
async resume() {}
})
new PearSuspension(opts)Creates instance. Wires Bare.on('suspend'/'resume'/'wakeup'). Calls Bare.idle() after suspend if not interrupted.
Options:
store — optional, called .suspend() on suspendswarm — optional, called .suspend() on suspendpollLinger() — optional, returns ms left to lingersuspend() — optional, called after store/swarmresume() — optional, called on resumeverbose — optional, default falsesus.suspend(ms)Wait up to ms then suspend.
sus.resume()Resume ASAP.
sus.wakeup()Wake up then re-suspend.
Apache-2.0