@lvce-editor/pty-host 0.20.10 → 0.20.11
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/package.json
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as Assert from '../Assert/Assert.js'
|
|
2
2
|
import * as Id from '../Id/Id.js'
|
|
3
|
+
import * as Logger from '../Logger/Logger.js'
|
|
4
|
+
import * as Promises from '../Promises/Promises.js'
|
|
3
5
|
|
|
4
6
|
export const state = {
|
|
5
7
|
callbacks: Object.create(null),
|
|
@@ -7,36 +9,18 @@ export const state = {
|
|
|
7
9
|
|
|
8
10
|
export const registerPromise = () => {
|
|
9
11
|
const id = Id.create()
|
|
10
|
-
const promise =
|
|
11
|
-
|
|
12
|
-
resolve,
|
|
13
|
-
reject,
|
|
14
|
-
}
|
|
15
|
-
})
|
|
12
|
+
const { resolve, promise } = Promises.withResolvers()
|
|
13
|
+
state.callbacks[id] = resolve
|
|
16
14
|
return { id, promise }
|
|
17
15
|
}
|
|
18
16
|
|
|
19
|
-
export const unregister = (id) => {
|
|
20
|
-
delete state.callbacks[id]
|
|
21
|
-
}
|
|
22
|
-
|
|
23
17
|
export const resolve = (id, args) => {
|
|
24
18
|
Assert.number(id)
|
|
25
19
|
if (!(id in state.callbacks)) {
|
|
26
20
|
console.log(args)
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
state.callbacks[id].resolve(args)
|
|
31
|
-
delete state.callbacks[id]
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const reject = (id, error) => {
|
|
35
|
-
Assert.number(id)
|
|
36
|
-
if (!(id in state.callbacks)) {
|
|
37
|
-
console.warn(`callback ${id} may already be disposed`)
|
|
21
|
+
Logger.warn(`callback ${id} may already be disposed`)
|
|
38
22
|
return
|
|
39
23
|
}
|
|
40
|
-
state.callbacks[id]
|
|
24
|
+
state.callbacks[id](args)
|
|
41
25
|
delete state.callbacks[id]
|
|
42
26
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const withResolvers = () => {
|
|
2
|
+
/**
|
|
3
|
+
* @type {any}
|
|
4
|
+
*/
|
|
5
|
+
let _resolve
|
|
6
|
+
/**
|
|
7
|
+
* @type {any}
|
|
8
|
+
*/
|
|
9
|
+
let _reject
|
|
10
|
+
const promise = new Promise((resolve, reject) => {
|
|
11
|
+
_resolve = resolve
|
|
12
|
+
_reject = reject
|
|
13
|
+
})
|
|
14
|
+
return {
|
|
15
|
+
resolve: _resolve,
|
|
16
|
+
reject: _reject,
|
|
17
|
+
promise,
|
|
18
|
+
}
|
|
19
|
+
}
|