@meshagent/meshagent 0.5.6 → 0.5.8
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/CHANGELOG.md +6 -0
- package/dist/browser/stream-controller.d.ts +1 -2
- package/dist/browser/stream-controller.js +57 -23
- package/dist/esm/stream-controller.d.ts +1 -2
- package/dist/esm/stream-controller.js +57 -23
- package/dist/node/stream-controller.d.ts +1 -2
- package/dist/node/stream-controller.js +57 -23
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,51 +4,85 @@ exports.StreamController = void 0;
|
|
|
4
4
|
class StreamController {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.closed = false;
|
|
7
|
-
this.
|
|
8
|
-
this.waiters = [];
|
|
7
|
+
this.subs = new Set();
|
|
9
8
|
}
|
|
10
9
|
get stream() {
|
|
11
10
|
const self = this;
|
|
12
11
|
return {
|
|
13
12
|
[Symbol.asyncIterator]() {
|
|
13
|
+
const sub = {
|
|
14
|
+
queue: [],
|
|
15
|
+
waiter: null
|
|
16
|
+
};
|
|
17
|
+
self.subs.add(sub);
|
|
18
|
+
const cleanup = () => {
|
|
19
|
+
if (sub.waiter) {
|
|
20
|
+
const w = sub.waiter;
|
|
21
|
+
sub.waiter = null;
|
|
22
|
+
w({ done: true, value: undefined });
|
|
23
|
+
}
|
|
24
|
+
self.subs.delete(sub);
|
|
25
|
+
};
|
|
14
26
|
return {
|
|
15
27
|
async next() {
|
|
16
|
-
if (
|
|
17
|
-
return {
|
|
18
|
-
done: false,
|
|
19
|
-
value: self.queue.shift()
|
|
20
|
-
};
|
|
28
|
+
if (sub.queue.length > 0) {
|
|
29
|
+
return { done: false, value: sub.queue.shift() };
|
|
21
30
|
}
|
|
22
31
|
if (self.closed) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
value: undefined
|
|
26
|
-
};
|
|
32
|
+
cleanup();
|
|
33
|
+
return { done: true, value: undefined };
|
|
27
34
|
}
|
|
28
|
-
return new Promise(
|
|
29
|
-
|
|
35
|
+
return new Promise(resolve => {
|
|
36
|
+
sub.waiter = resolve;
|
|
30
37
|
});
|
|
31
38
|
},
|
|
39
|
+
async return() {
|
|
40
|
+
cleanup();
|
|
41
|
+
return {
|
|
42
|
+
done: true,
|
|
43
|
+
value: undefined
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
async throw(e) {
|
|
47
|
+
cleanup();
|
|
48
|
+
return Promise.reject(e);
|
|
49
|
+
}
|
|
32
50
|
};
|
|
33
|
-
}
|
|
51
|
+
}
|
|
34
52
|
};
|
|
35
53
|
}
|
|
36
54
|
add(value) {
|
|
37
55
|
if (this.closed)
|
|
38
56
|
return;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
for (const sub of [...this.subs]) {
|
|
58
|
+
if (sub.waiter) {
|
|
59
|
+
const w = sub.waiter;
|
|
60
|
+
sub.waiter = null;
|
|
61
|
+
try {
|
|
62
|
+
w({ done: false, value });
|
|
63
|
+
}
|
|
64
|
+
catch { }
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
sub.queue.push(value);
|
|
68
|
+
}
|
|
45
69
|
}
|
|
46
70
|
}
|
|
47
71
|
close() {
|
|
72
|
+
if (this.closed)
|
|
73
|
+
return;
|
|
48
74
|
this.closed = true;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
75
|
+
for (const sub of [...this.subs]) {
|
|
76
|
+
if (sub.waiter) {
|
|
77
|
+
const w = sub.waiter;
|
|
78
|
+
sub.waiter = null;
|
|
79
|
+
try {
|
|
80
|
+
w({ done: true, value: undefined });
|
|
81
|
+
}
|
|
82
|
+
catch { }
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
}
|
|
52
86
|
}
|
|
53
87
|
}
|
|
54
88
|
}
|
|
@@ -1,51 +1,85 @@
|
|
|
1
1
|
export class StreamController {
|
|
2
2
|
constructor() {
|
|
3
3
|
this.closed = false;
|
|
4
|
-
this.
|
|
5
|
-
this.waiters = [];
|
|
4
|
+
this.subs = new Set();
|
|
6
5
|
}
|
|
7
6
|
get stream() {
|
|
8
7
|
const self = this;
|
|
9
8
|
return {
|
|
10
9
|
[Symbol.asyncIterator]() {
|
|
10
|
+
const sub = {
|
|
11
|
+
queue: [],
|
|
12
|
+
waiter: null
|
|
13
|
+
};
|
|
14
|
+
self.subs.add(sub);
|
|
15
|
+
const cleanup = () => {
|
|
16
|
+
if (sub.waiter) {
|
|
17
|
+
const w = sub.waiter;
|
|
18
|
+
sub.waiter = null;
|
|
19
|
+
w({ done: true, value: undefined });
|
|
20
|
+
}
|
|
21
|
+
self.subs.delete(sub);
|
|
22
|
+
};
|
|
11
23
|
return {
|
|
12
24
|
async next() {
|
|
13
|
-
if (
|
|
14
|
-
return {
|
|
15
|
-
done: false,
|
|
16
|
-
value: self.queue.shift()
|
|
17
|
-
};
|
|
25
|
+
if (sub.queue.length > 0) {
|
|
26
|
+
return { done: false, value: sub.queue.shift() };
|
|
18
27
|
}
|
|
19
28
|
if (self.closed) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
value: undefined
|
|
23
|
-
};
|
|
29
|
+
cleanup();
|
|
30
|
+
return { done: true, value: undefined };
|
|
24
31
|
}
|
|
25
|
-
return new Promise(
|
|
26
|
-
|
|
32
|
+
return new Promise(resolve => {
|
|
33
|
+
sub.waiter = resolve;
|
|
27
34
|
});
|
|
28
35
|
},
|
|
36
|
+
async return() {
|
|
37
|
+
cleanup();
|
|
38
|
+
return {
|
|
39
|
+
done: true,
|
|
40
|
+
value: undefined
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
async throw(e) {
|
|
44
|
+
cleanup();
|
|
45
|
+
return Promise.reject(e);
|
|
46
|
+
}
|
|
29
47
|
};
|
|
30
|
-
}
|
|
48
|
+
}
|
|
31
49
|
};
|
|
32
50
|
}
|
|
33
51
|
add(value) {
|
|
34
52
|
if (this.closed)
|
|
35
53
|
return;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
for (const sub of [...this.subs]) {
|
|
55
|
+
if (sub.waiter) {
|
|
56
|
+
const w = sub.waiter;
|
|
57
|
+
sub.waiter = null;
|
|
58
|
+
try {
|
|
59
|
+
w({ done: false, value });
|
|
60
|
+
}
|
|
61
|
+
catch { }
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
sub.queue.push(value);
|
|
65
|
+
}
|
|
42
66
|
}
|
|
43
67
|
}
|
|
44
68
|
close() {
|
|
69
|
+
if (this.closed)
|
|
70
|
+
return;
|
|
45
71
|
this.closed = true;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
for (const sub of [...this.subs]) {
|
|
73
|
+
if (sub.waiter) {
|
|
74
|
+
const w = sub.waiter;
|
|
75
|
+
sub.waiter = null;
|
|
76
|
+
try {
|
|
77
|
+
w({ done: true, value: undefined });
|
|
78
|
+
}
|
|
79
|
+
catch { }
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
}
|
|
49
83
|
}
|
|
50
84
|
}
|
|
51
85
|
}
|
|
@@ -4,51 +4,85 @@ exports.StreamController = void 0;
|
|
|
4
4
|
class StreamController {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.closed = false;
|
|
7
|
-
this.
|
|
8
|
-
this.waiters = [];
|
|
7
|
+
this.subs = new Set();
|
|
9
8
|
}
|
|
10
9
|
get stream() {
|
|
11
10
|
const self = this;
|
|
12
11
|
return {
|
|
13
12
|
[Symbol.asyncIterator]() {
|
|
13
|
+
const sub = {
|
|
14
|
+
queue: [],
|
|
15
|
+
waiter: null
|
|
16
|
+
};
|
|
17
|
+
self.subs.add(sub);
|
|
18
|
+
const cleanup = () => {
|
|
19
|
+
if (sub.waiter) {
|
|
20
|
+
const w = sub.waiter;
|
|
21
|
+
sub.waiter = null;
|
|
22
|
+
w({ done: true, value: undefined });
|
|
23
|
+
}
|
|
24
|
+
self.subs.delete(sub);
|
|
25
|
+
};
|
|
14
26
|
return {
|
|
15
27
|
async next() {
|
|
16
|
-
if (
|
|
17
|
-
return {
|
|
18
|
-
done: false,
|
|
19
|
-
value: self.queue.shift()
|
|
20
|
-
};
|
|
28
|
+
if (sub.queue.length > 0) {
|
|
29
|
+
return { done: false, value: sub.queue.shift() };
|
|
21
30
|
}
|
|
22
31
|
if (self.closed) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
value: undefined
|
|
26
|
-
};
|
|
32
|
+
cleanup();
|
|
33
|
+
return { done: true, value: undefined };
|
|
27
34
|
}
|
|
28
|
-
return new Promise(
|
|
29
|
-
|
|
35
|
+
return new Promise(resolve => {
|
|
36
|
+
sub.waiter = resolve;
|
|
30
37
|
});
|
|
31
38
|
},
|
|
39
|
+
async return() {
|
|
40
|
+
cleanup();
|
|
41
|
+
return {
|
|
42
|
+
done: true,
|
|
43
|
+
value: undefined
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
async throw(e) {
|
|
47
|
+
cleanup();
|
|
48
|
+
return Promise.reject(e);
|
|
49
|
+
}
|
|
32
50
|
};
|
|
33
|
-
}
|
|
51
|
+
}
|
|
34
52
|
};
|
|
35
53
|
}
|
|
36
54
|
add(value) {
|
|
37
55
|
if (this.closed)
|
|
38
56
|
return;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
for (const sub of [...this.subs]) {
|
|
58
|
+
if (sub.waiter) {
|
|
59
|
+
const w = sub.waiter;
|
|
60
|
+
sub.waiter = null;
|
|
61
|
+
try {
|
|
62
|
+
w({ done: false, value });
|
|
63
|
+
}
|
|
64
|
+
catch { }
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
sub.queue.push(value);
|
|
68
|
+
}
|
|
45
69
|
}
|
|
46
70
|
}
|
|
47
71
|
close() {
|
|
72
|
+
if (this.closed)
|
|
73
|
+
return;
|
|
48
74
|
this.closed = true;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
75
|
+
for (const sub of [...this.subs]) {
|
|
76
|
+
if (sub.waiter) {
|
|
77
|
+
const w = sub.waiter;
|
|
78
|
+
sub.waiter = null;
|
|
79
|
+
try {
|
|
80
|
+
w({ done: true, value: undefined });
|
|
81
|
+
}
|
|
82
|
+
catch { }
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
}
|
|
52
86
|
}
|
|
53
87
|
}
|
|
54
88
|
}
|