starpc 0.26.0 → 0.26.1
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Duplex, Source } from 'it-stream-types';
|
|
2
2
|
import { StreamConn, StreamConnParams } from './conn.js';
|
|
3
3
|
import { Server } from './server';
|
|
4
|
-
export declare class MessagePortDuplex<T> implements Duplex<AsyncGenerator<T>, Source<T>, Promise<void>> {
|
|
4
|
+
export declare class MessagePortDuplex<T extends {}> implements Duplex<AsyncGenerator<T>, Source<T>, Promise<void>> {
|
|
5
5
|
readonly port: MessagePort;
|
|
6
6
|
sink: (source: Source<T>) => Promise<void>;
|
|
7
7
|
source: AsyncGenerator<T>;
|
|
@@ -10,7 +10,7 @@ export declare class MessagePortDuplex<T> implements Duplex<AsyncGenerator<T>, S
|
|
|
10
10
|
private _createSink;
|
|
11
11
|
private _createSource;
|
|
12
12
|
}
|
|
13
|
-
export declare function newMessagePortDuplex<T>(port: MessagePort): MessagePortDuplex<T>;
|
|
13
|
+
export declare function newMessagePortDuplex<T extends {}>(port: MessagePort): MessagePortDuplex<T>;
|
|
14
14
|
export declare class MessagePortConn extends StreamConn {
|
|
15
15
|
private _messagePort;
|
|
16
16
|
constructor(port: MessagePort, server?: Server, connParams?: StreamConnParams);
|
|
@@ -5,7 +5,8 @@ import { combineUint8ArrayListTransform } from './array-list.js';
|
|
|
5
5
|
// MessagePortDuplex is a AsyncIterable wrapper for MessagePort.
|
|
6
6
|
//
|
|
7
7
|
// When the sink is closed, the message port will also be closed.
|
|
8
|
-
//
|
|
8
|
+
// null will be written through the channel to indicate closure when the sink is closed.
|
|
9
|
+
// Note: there is no way to know for sure when a MessagePort is closed!
|
|
9
10
|
// You will need an additional keep-alive on top of MessagePortDuplex.
|
|
10
11
|
export class MessagePortDuplex {
|
|
11
12
|
constructor(port) {
|
|
@@ -46,6 +47,7 @@ export class MessagePortDuplex {
|
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
49
|
this.port.addEventListener('message', messageListener);
|
|
50
|
+
this.port.start();
|
|
49
51
|
return () => {
|
|
50
52
|
this.port.removeEventListener('message', messageListener);
|
|
51
53
|
};
|
package/package.json
CHANGED
package/srpc/message-port.ts
CHANGED
|
@@ -9,9 +9,10 @@ import { combineUint8ArrayListTransform } from './array-list.js'
|
|
|
9
9
|
// MessagePortDuplex is a AsyncIterable wrapper for MessagePort.
|
|
10
10
|
//
|
|
11
11
|
// When the sink is closed, the message port will also be closed.
|
|
12
|
-
//
|
|
12
|
+
// null will be written through the channel to indicate closure when the sink is closed.
|
|
13
|
+
// Note: there is no way to know for sure when a MessagePort is closed!
|
|
13
14
|
// You will need an additional keep-alive on top of MessagePortDuplex.
|
|
14
|
-
export class MessagePortDuplex<T>
|
|
15
|
+
export class MessagePortDuplex<T extends {}>
|
|
15
16
|
implements Duplex<AsyncGenerator<T>, Source<T>, Promise<void>>
|
|
16
17
|
{
|
|
17
18
|
// port is the message port
|
|
@@ -62,6 +63,8 @@ export class MessagePortDuplex<T>
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
this.port.addEventListener('message', messageListener)
|
|
66
|
+
this.port.start()
|
|
67
|
+
|
|
65
68
|
return () => {
|
|
66
69
|
this.port.removeEventListener('message', messageListener)
|
|
67
70
|
}
|
|
@@ -81,7 +84,7 @@ export class MessagePortDuplex<T>
|
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
// newMessagePortDuplex constructs a MessagePortDuplex with a channel name.
|
|
84
|
-
export function newMessagePortDuplex<T>(
|
|
87
|
+
export function newMessagePortDuplex<T extends {}>(
|
|
85
88
|
port: MessagePort,
|
|
86
89
|
): MessagePortDuplex<T> {
|
|
87
90
|
return new MessagePortDuplex<T>(port)
|