pear-suspension
v0.0.3
Published
Handle suspend/resume for Pear apps with p2p modules lifecycle hooks
Readme
pear-suspension
Suspendify wrapper for Pear threads. Handles Bare suspend/resume/wakeup events in the child, with optional store and swarm hooks.
npm install pear-suspensionUsage
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() {}
})API
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, defaultfalse
sus.suspend(ms)
Wait up to ms then suspend.
sus.resume()
Resume ASAP.
sus.wakeup()
Wake up then re-suspend.
License
Apache-2.0
