passive-core-watcher 1.0.1 → 1.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 +7 -5
- package/package.json +6 -3
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const IdEnc = require('hypercore-id-encoding')
|
|
|
6
6
|
const safetyCatch = require('safety-catch')
|
|
7
7
|
|
|
8
8
|
class PassiveCoreWatcher extends EventEmitter {
|
|
9
|
-
constructor
|
|
9
|
+
constructor(corestore, { watch, open }) {
|
|
10
10
|
super()
|
|
11
11
|
this.store = corestore
|
|
12
12
|
this.watch = watch
|
|
@@ -27,7 +27,7 @@ class PassiveCoreWatcher extends EventEmitter {
|
|
|
27
27
|
})
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
destroy
|
|
30
|
+
destroy() {
|
|
31
31
|
this.destroyed = true
|
|
32
32
|
this.store.unwatch(this._oncoreopenBound)
|
|
33
33
|
for (const core of this._openCores.values()) {
|
|
@@ -35,7 +35,8 @@ class PassiveCoreWatcher extends EventEmitter {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
async _oncoreopen
|
|
38
|
+
async _oncoreopen(core) {
|
|
39
|
+
// not allowed to throw
|
|
39
40
|
try {
|
|
40
41
|
if (await this.watch(core)) {
|
|
41
42
|
await core.ready()
|
|
@@ -46,7 +47,7 @@ class PassiveCoreWatcher extends EventEmitter {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
async ensureTracked
|
|
50
|
+
async ensureTracked(key) {
|
|
50
51
|
key = IdEnc.decode(key)
|
|
51
52
|
|
|
52
53
|
const discKey = b4a.toString(HypCrypto.discoveryKey(key), 'hex')
|
|
@@ -59,7 +60,8 @@ class PassiveCoreWatcher extends EventEmitter {
|
|
|
59
60
|
// Must be sync up till the line above, for the accounting
|
|
60
61
|
|
|
61
62
|
await session.ready()
|
|
62
|
-
if (session.closing) {
|
|
63
|
+
if (session.closing) {
|
|
64
|
+
// race condition (insta close)
|
|
63
65
|
this._openCores.delete(discKey)
|
|
64
66
|
return
|
|
65
67
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passive-core-watcher",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Run conditional logic on a corestore's hypercores",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"
|
|
7
|
+
"format": "prettier --write .",
|
|
8
|
+
"test": "prettier --check . && lunte && brittle test.js"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -32,7 +33,9 @@
|
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"brittle": "^3.10.0",
|
|
34
35
|
"corestore": "^7.0.0",
|
|
35
|
-
"
|
|
36
|
+
"lunte": "^1.6.0",
|
|
37
|
+
"prettier": "^3.6.2",
|
|
38
|
+
"prettier-config-holepunch": "^2.0.0",
|
|
36
39
|
"test-tmp": "^1.4.0"
|
|
37
40
|
},
|
|
38
41
|
"dependencies": {
|