pear-suspension 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +24 -24
- package/package.json +2 -4
package/index.js
CHANGED
|
@@ -6,17 +6,18 @@ class PearSuspension extends Suspendify {
|
|
|
6
6
|
if (typeof Bare === 'undefined' || typeof Bare.on !== 'function') {
|
|
7
7
|
throw new Error('PearSuspension requires global Bare')
|
|
8
8
|
}
|
|
9
|
-
const { store, swarm, pollLinger,
|
|
10
|
-
|
|
9
|
+
const { store, swarm, pollLinger, verbose = false, wakeupLinger } = opts
|
|
10
|
+
let selfRef
|
|
11
11
|
const log = verbose ? console.log.bind(console) : () => {}
|
|
12
12
|
super({
|
|
13
13
|
pollLinger,
|
|
14
|
+
...(wakeupLinger !== undefined && { wakeupLinger }),
|
|
14
15
|
async suspend() {
|
|
15
16
|
log('Suspending...')
|
|
16
|
-
if (
|
|
17
|
-
if (
|
|
18
|
-
await suspend()
|
|
19
|
-
if (selfRef
|
|
17
|
+
if (swarm && typeof swarm.suspend === 'function') await swarm.suspend()
|
|
18
|
+
if (store && typeof store.suspend === 'function') await store.suspend()
|
|
19
|
+
if (opts.suspend && typeof opts.suspend === 'function') await opts.suspend()
|
|
20
|
+
if (selfRef?.interrupted) {
|
|
20
21
|
log('interrupted skipping idle')
|
|
21
22
|
} else if (typeof Bare.idle === 'function') {
|
|
22
23
|
log('Asking bare to go Idle')
|
|
@@ -25,38 +26,37 @@ class PearSuspension extends Suspendify {
|
|
|
25
26
|
},
|
|
26
27
|
async resume() {
|
|
27
28
|
log('Resuming...')
|
|
28
|
-
await resume()
|
|
29
|
+
if (store && typeof store.resume === 'function') await store.resume()
|
|
30
|
+
if (swarm && typeof swarm.resume === 'function') await swarm.resume()
|
|
31
|
+
if (opts.resume && typeof opts.resume === 'function') await opts.resume()
|
|
29
32
|
log('Resuming concluded')
|
|
33
|
+
},
|
|
34
|
+
async wakeup() {
|
|
35
|
+
log('Waking up...')
|
|
36
|
+
if (opts.wakeup && typeof opts.wakeup === 'function') await opts.wakeup()
|
|
37
|
+
log('Wakeup concluded')
|
|
30
38
|
}
|
|
31
39
|
})
|
|
32
|
-
selfRef
|
|
40
|
+
selfRef = this
|
|
33
41
|
this.verbose = verbose
|
|
34
42
|
|
|
35
43
|
Bare.on('idle', function () {
|
|
36
|
-
|
|
44
|
+
console.log('Bare has fully idled, zzz....')
|
|
37
45
|
})
|
|
38
46
|
|
|
39
|
-
Bare.on('suspend', (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
log('Asking suspendify to suspend')
|
|
43
|
-
this.suspend(ms)
|
|
47
|
+
Bare.on('suspend', async (ms) => {
|
|
48
|
+
log('Waiting for suspendify to suspend')
|
|
49
|
+
await this.suspend(ms === undefined || ms === null ? 0 : Math.max(0, ms))
|
|
44
50
|
})
|
|
45
|
-
Bare.on('resume', () => {
|
|
51
|
+
Bare.on('resume', async () => {
|
|
46
52
|
log('Bare resume')
|
|
47
|
-
this.resume()
|
|
53
|
+
await this.resume()
|
|
48
54
|
})
|
|
49
|
-
Bare.on('wakeup', () => {
|
|
55
|
+
Bare.on('wakeup', async () => {
|
|
50
56
|
log('Bare wakeup')
|
|
51
|
-
this.wakeup()
|
|
57
|
+
await this.wakeup()
|
|
52
58
|
})
|
|
53
59
|
}
|
|
54
|
-
|
|
55
|
-
isBackgrounded() {
|
|
56
|
-
return this.suspended || this.suspending
|
|
57
|
-
}
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
function noop() {}
|
|
61
|
-
|
|
62
62
|
module.exports = PearSuspension
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pear-suspension",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Handle suspend/resume for Pear apps with p2p modules lifecycle hooks",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"exports": {
|
|
@@ -16,9 +16,7 @@
|
|
|
16
16
|
"index.d.ts"
|
|
17
17
|
],
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"bare-channel": "^2.
|
|
20
|
-
"bare-pipe": "^4.1.3",
|
|
21
|
-
"bare-subprocess": "^5.0.0",
|
|
19
|
+
"bare-channel": "^5.2.3",
|
|
22
20
|
"brittle": "^3.19.0",
|
|
23
21
|
"lunte": "^1.2.0",
|
|
24
22
|
"prettier": "^3.6.2",
|