@livestore/webmesh 0.3.0-dev.46 → 0.3.0-dev.47
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/dist/.tsbuildinfo +1 -1
- package/dist/common.d.ts +10 -10
- package/dist/websocket-edge.d.ts +8 -5
- package/dist/websocket-edge.d.ts.map +1 -1
- package/dist/websocket-edge.js +11 -8
- package/dist/websocket-edge.js.map +1 -1
- package/package.json +3 -3
- package/src/websocket-edge.ts +14 -7
package/dist/common.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare class EdgeAlreadyExistsError extends EdgeAlreadyExistsError_base
|
|
|
20
20
|
}
|
|
21
21
|
export declare const packetAsOtelAttributes: (packet: typeof Packet.Type) => {
|
|
22
22
|
packet?: {
|
|
23
|
+
readonly _tag: "DirectChannelRequest";
|
|
23
24
|
readonly remainingHops?: readonly string[] | undefined;
|
|
24
25
|
readonly channelVersion: number;
|
|
25
26
|
readonly reqId: string | undefined;
|
|
@@ -29,8 +30,8 @@ export declare const packetAsOtelAttributes: (packet: typeof Packet.Type) => {
|
|
|
29
30
|
readonly source: string;
|
|
30
31
|
readonly channelName: string;
|
|
31
32
|
readonly hops: readonly string[];
|
|
32
|
-
readonly _tag: "DirectChannelRequest";
|
|
33
33
|
} | {
|
|
34
|
+
readonly _tag: "DirectChannelResponseNoTransferables";
|
|
34
35
|
readonly remainingHops: readonly string[];
|
|
35
36
|
readonly reqId: string;
|
|
36
37
|
readonly id: string;
|
|
@@ -38,17 +39,17 @@ export declare const packetAsOtelAttributes: (packet: typeof Packet.Type) => {
|
|
|
38
39
|
readonly source: string;
|
|
39
40
|
readonly channelName: string;
|
|
40
41
|
readonly hops: readonly string[];
|
|
41
|
-
readonly _tag: "DirectChannelResponseNoTransferables";
|
|
42
42
|
} | {
|
|
43
|
+
readonly _tag: "ProxyChannelRequest";
|
|
43
44
|
readonly remainingHops?: undefined;
|
|
44
45
|
readonly id: string;
|
|
45
46
|
readonly target: string;
|
|
46
47
|
readonly source: string;
|
|
47
48
|
readonly channelName: string;
|
|
48
49
|
readonly hops: readonly string[];
|
|
49
|
-
readonly _tag: "ProxyChannelRequest";
|
|
50
50
|
readonly channelIdCandidate: string;
|
|
51
51
|
} | {
|
|
52
|
+
readonly _tag: "ProxyChannelResponseSuccess";
|
|
52
53
|
readonly remainingHops: readonly string[];
|
|
53
54
|
readonly reqId: string;
|
|
54
55
|
readonly id: string;
|
|
@@ -56,10 +57,10 @@ export declare const packetAsOtelAttributes: (packet: typeof Packet.Type) => {
|
|
|
56
57
|
readonly source: string;
|
|
57
58
|
readonly channelName: string;
|
|
58
59
|
readonly hops: readonly string[];
|
|
59
|
-
readonly _tag: "ProxyChannelResponseSuccess";
|
|
60
60
|
readonly channelIdCandidate: string;
|
|
61
61
|
readonly combinedChannelId: string;
|
|
62
62
|
} | {
|
|
63
|
+
readonly _tag: "ProxyChannelPayloadAck";
|
|
63
64
|
readonly remainingHops: readonly string[];
|
|
64
65
|
readonly reqId: string;
|
|
65
66
|
readonly id: string;
|
|
@@ -67,36 +68,35 @@ export declare const packetAsOtelAttributes: (packet: typeof Packet.Type) => {
|
|
|
67
68
|
readonly source: string;
|
|
68
69
|
readonly channelName: string;
|
|
69
70
|
readonly hops: readonly string[];
|
|
70
|
-
readonly _tag: "ProxyChannelPayloadAck";
|
|
71
71
|
readonly combinedChannelId: string;
|
|
72
72
|
} | {
|
|
73
|
+
readonly _tag: "NetworkEdgeAdded";
|
|
73
74
|
readonly id: string;
|
|
74
75
|
readonly target: string;
|
|
75
76
|
readonly source: string;
|
|
76
|
-
readonly _tag: "NetworkEdgeAdded";
|
|
77
77
|
} | {
|
|
78
|
+
readonly _tag: "NetworkTopologyRequest";
|
|
78
79
|
readonly id: string;
|
|
79
80
|
readonly target: "-";
|
|
80
81
|
readonly source: string;
|
|
81
82
|
readonly hops: readonly string[];
|
|
82
|
-
readonly _tag: "NetworkTopologyRequest";
|
|
83
83
|
} | {
|
|
84
|
+
readonly _tag: "NetworkTopologyResponse";
|
|
84
85
|
readonly remainingHops: readonly string[];
|
|
85
86
|
readonly reqId: string;
|
|
86
87
|
readonly id: string;
|
|
87
88
|
readonly target: "-";
|
|
88
89
|
readonly source: string;
|
|
89
|
-
readonly _tag: "NetworkTopologyResponse";
|
|
90
90
|
readonly nodeName: string;
|
|
91
91
|
readonly edges: readonly string[];
|
|
92
92
|
} | {
|
|
93
|
+
readonly _tag: "BroadcastChannelPacket";
|
|
94
|
+
readonly payload: any;
|
|
93
95
|
readonly id: string;
|
|
94
96
|
readonly target: "-";
|
|
95
97
|
readonly source: string;
|
|
96
98
|
readonly channelName: string;
|
|
97
99
|
readonly hops: readonly string[];
|
|
98
|
-
readonly _tag: "BroadcastChannelPacket";
|
|
99
|
-
readonly payload: any;
|
|
100
100
|
} | undefined;
|
|
101
101
|
packetId: string;
|
|
102
102
|
'span.label': string;
|
package/dist/websocket-edge.d.ts
CHANGED
|
@@ -17,19 +17,19 @@ declare const WSEdgeMessage_base: Schema.Union<[typeof WSEdgeInit, typeof WSEdge
|
|
|
17
17
|
export declare class WSEdgeMessage extends WSEdgeMessage_base {
|
|
18
18
|
}
|
|
19
19
|
export declare const MessageMsgPack: Schema.transform<typeof Schema.Uint8ArrayFromSelf, Schema.Schema<{
|
|
20
|
-
readonly _tag: "WSEdgeInit";
|
|
21
20
|
readonly from: string;
|
|
21
|
+
readonly _tag: "WSEdgeInit";
|
|
22
22
|
} | {
|
|
23
|
+
readonly from: string;
|
|
23
24
|
readonly _tag: "WSEdgePayload";
|
|
24
25
|
readonly payload: any;
|
|
25
|
-
readonly from: string;
|
|
26
26
|
}, {
|
|
27
|
-
readonly _tag: "WSEdgeInit";
|
|
28
27
|
readonly from: string;
|
|
28
|
+
readonly _tag: "WSEdgeInit";
|
|
29
29
|
} | {
|
|
30
|
+
readonly from: string;
|
|
30
31
|
readonly _tag: "WSEdgePayload";
|
|
31
32
|
readonly payload: any;
|
|
32
|
-
readonly from: string;
|
|
33
33
|
}, never>>;
|
|
34
34
|
export type SocketType = {
|
|
35
35
|
_tag: 'leaf';
|
|
@@ -42,9 +42,12 @@ export declare const connectViaWebSocket: ({ node, url, openTimeout, }: {
|
|
|
42
42
|
url: string;
|
|
43
43
|
openTimeout?: number;
|
|
44
44
|
}) => Effect.Effect<void, never, Scope.Scope | HttpClient.HttpClient>;
|
|
45
|
-
export declare const makeWebSocketEdge: ({ socket, socketType, }: {
|
|
45
|
+
export declare const makeWebSocketEdge: ({ socket, socketType, debug: debugInfo, }: {
|
|
46
46
|
socket: Socket.Socket;
|
|
47
47
|
socketType: SocketType;
|
|
48
|
+
debug?: {
|
|
49
|
+
id?: string;
|
|
50
|
+
};
|
|
48
51
|
}) => Effect.Effect<{
|
|
49
52
|
webChannel: WebChannel.WebChannel<typeof WebmeshSchema.Packet.Type, typeof WebmeshSchema.Packet.Type>;
|
|
50
53
|
from: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-edge.d.ts","sourceRoot":"","sources":["../src/websocket-edge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAEL,MAAM,EAMN,MAAM,EACN,KAAK,EACL,MAAM,EAEN,UAAU,EACX,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAA;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;;;;AAEzC,qBAAa,UAAW,SAAQ,eAE9B;CAAG;;;;;AAEL,qBAAa,aAAc,SAAQ,kBAGjC;CAAG;;AAEL,qBAAa,aAAc,SAAQ,kBAAuC;CAAG;AAE7E,eAAO,MAAM,cAAc;;;;;;;;;;;;;;UAAgC,CAAA;AAE3D,MAAM,MAAM,UAAU,GAClB;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb,GACD;IACE,IAAI,EAAE,OAAO,CAAA;C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,MAAM,CAAA;IACrB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,CAAC,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACxB,KAAG,MAAM,CAAC,MAAM,CACf;IACE,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACrG,IAAI,EAAE,MAAM,CAAA;CACb,EACD,KAAK,EACL,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,UAAU,CAuGlC,CAAA"}
|
package/dist/websocket-edge.js
CHANGED
|
@@ -13,36 +13,36 @@ export class WSEdgeMessage extends Schema.Union(WSEdgeInit, WSEdgePayload) {
|
|
|
13
13
|
}
|
|
14
14
|
export const MessageMsgPack = Schema.MsgPack(WSEdgeMessage);
|
|
15
15
|
export const connectViaWebSocket = ({ node, url, openTimeout, }) => Effect.gen(function* () {
|
|
16
|
-
const disconnected = yield* Deferred.make();
|
|
17
16
|
const socket = yield* Socket.makeWebSocket(url, { openTimeout });
|
|
18
17
|
const edgeChannel = yield* makeWebSocketEdge({
|
|
19
18
|
socket,
|
|
20
19
|
socketType: { _tag: 'leaf', from: node.nodeName },
|
|
20
|
+
debug: { id: `node:${node.nodeName}` },
|
|
21
21
|
});
|
|
22
22
|
yield* node
|
|
23
23
|
.addEdge({ target: 'ws', edgeChannel: edgeChannel.webChannel, replaceIfExists: true })
|
|
24
24
|
.pipe(Effect.acquireRelease(() => node.removeEdge('ws').pipe(Effect.orDie)));
|
|
25
|
-
yield*
|
|
25
|
+
yield* edgeChannel.webChannel.closedDeferred;
|
|
26
26
|
}).pipe(Effect.scoped, Effect.forever, Effect.interruptible, Effect.provide(binaryWebSocketConstructorLayer));
|
|
27
27
|
const binaryWebSocketConstructorLayer = Layer.succeed(Socket.WebSocketConstructor, (url, protocols) => {
|
|
28
28
|
const socket = new globalThis.WebSocket(url, protocols);
|
|
29
29
|
socket.binaryType = 'arraybuffer';
|
|
30
30
|
return socket;
|
|
31
31
|
});
|
|
32
|
-
export const makeWebSocketEdge = ({ socket, socketType, }) => Effect.scopeWithCloseable((scope) => Effect.gen(function* () {
|
|
32
|
+
export const makeWebSocketEdge = ({ socket, socketType, debug: debugInfo, }) => Effect.scopeWithCloseable((scope) => Effect.gen(function* () {
|
|
33
33
|
const fromDeferred = yield* Deferred.make();
|
|
34
34
|
const listenQueue = yield* Queue.unbounded().pipe(Effect.acquireRelease(Queue.shutdown));
|
|
35
35
|
const schema = WebChannel.mapSchema(WebmeshSchema.Packet);
|
|
36
36
|
const isConnectedLatch = yield* Effect.makeLatch(true);
|
|
37
37
|
const closedDeferred = yield* Deferred.make().pipe(Effect.acquireRelease(Deferred.done(Exit.void)));
|
|
38
|
-
const retryOpenTimeoutSchedule = Schedule.exponential(100).pipe(Schedule.whileInput((_) => _.reason === 'OpenTimeout' || _.reason === 'Open'));
|
|
39
|
-
yield* Stream.never.pipe(Stream.pipeThroughChannel(Socket.toChannel(socket)), Stream.catchTag('SocketError', Effect.
|
|
40
|
-
// yield* Effect.logError(`[websocket-edge] Socket error`, error)
|
|
38
|
+
const retryOpenTimeoutSchedule = Schedule.union(Schedule.exponential(100), Schedule.spaced(5000)).pipe(Schedule.whileInput((_) => _.reason === 'OpenTimeout' || _.reason === 'Open'));
|
|
39
|
+
yield* Stream.never.pipe(Stream.pipeThroughChannel(Socket.toChannel(socket)), Stream.catchTag('SocketError', Effect.fnUntraced(function* (error) {
|
|
40
|
+
// yield* Effect.logError(`[websocket-edge] Socket error`, error, { socketType, debugId: debugInfo?.id })
|
|
41
41
|
// In the case of the socket being closed, we're interrupting the stream
|
|
42
42
|
// and close the WebChannel (which can be observed from the outside)
|
|
43
43
|
if (error.reason === 'Close') {
|
|
44
|
-
yield* isConnectedLatch.close;
|
|
45
44
|
yield* Deferred.succeed(closedDeferred, undefined);
|
|
45
|
+
yield* isConnectedLatch.close;
|
|
46
46
|
return yield* Effect.interrupt;
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
@@ -58,7 +58,10 @@ export const makeWebSocketEdge = ({ socket, socketType, }) => Effect.scopeWithCl
|
|
|
58
58
|
// yield* Effect.logDebug(`[websocket-edge] recv from ${msg.from}: ${decodedPayload._tag}`, decodedPayload)
|
|
59
59
|
yield* Queue.offer(listenQueue, decodedPayload);
|
|
60
60
|
}
|
|
61
|
-
})), Stream.runDrain, Effect.
|
|
61
|
+
})), Stream.runDrain, Effect.tap(Effect.fnUntraced(function* () {
|
|
62
|
+
yield* Deferred.succeed(closedDeferred, undefined);
|
|
63
|
+
yield* isConnectedLatch.close;
|
|
64
|
+
})), Effect.interruptible, Effect.withSpan('makeWebSocketEdge:listen'), Effect.tapCauseLogPretty, Effect.forkScoped);
|
|
62
65
|
const sendToSocket = yield* socket.writer;
|
|
63
66
|
const initHandshake = (from) => sendToSocket(Schema.encodeSync(MessageMsgPack)({ _tag: 'WSEdgeInit', from }));
|
|
64
67
|
if (socketType._tag === 'leaf') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-edge.js","sourceRoot":"","sources":["../src/websocket-edge.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,EACJ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,EACN,MAAM,EACN,UAAU,GACX,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAA;AAGjD,MAAM,OAAO,UAAW,SAAQ,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE;IAChE,IAAI,EAAE,MAAM,CAAC,MAAM;CACpB,CAAC;CAAG;AAEL,MAAM,OAAO,aAAc,SAAQ,MAAM,CAAC,YAAY,CAAC,eAAe,EAAE;IACtE,IAAI,EAAE,MAAM,CAAC,MAAM;IACnB,OAAO,EAAE,MAAM,CAAC,GAAG;CACpB,C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EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAClG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAEvB,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,IAAI,CAC/C,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EACxB,UAAU,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAC/C,CAAA;IAED,MAAM,UAAU,GAAG;QACjB,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE,UAAU,CAAC,gBAAgB;QAC1D,IAAI;QACJ,MAAM;QACN,cAAc;QACd,MAAM;QACN,qBAAqB,EAAE,KAAK;QAC5B,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC;KAC4D,CAAA;IAErG,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAA;AAC7B,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAClE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/webmesh",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.47",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
},
|
|
16
16
|
"types": "./dist/mod.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@livestore/utils": "0.3.0-dev.
|
|
18
|
+
"@livestore/utils": "0.3.0-dev.47"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"vitest": "^3.1.2",
|
|
22
|
-
"@livestore/utils-dev": "0.3.0-dev.
|
|
22
|
+
"@livestore/utils-dev": "0.3.0-dev.47"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
25
|
"package.json",
|
package/src/websocket-edge.ts
CHANGED
|
@@ -49,20 +49,19 @@ export const connectViaWebSocket = ({
|
|
|
49
49
|
openTimeout?: number
|
|
50
50
|
}): Effect.Effect<void, never, Scope.Scope | HttpClient.HttpClient> =>
|
|
51
51
|
Effect.gen(function* () {
|
|
52
|
-
const disconnected = yield* Deferred.make<void>()
|
|
53
|
-
|
|
54
52
|
const socket = yield* Socket.makeWebSocket(url, { openTimeout })
|
|
55
53
|
|
|
56
54
|
const edgeChannel = yield* makeWebSocketEdge({
|
|
57
55
|
socket,
|
|
58
56
|
socketType: { _tag: 'leaf', from: node.nodeName },
|
|
57
|
+
debug: { id: `node:${node.nodeName}` },
|
|
59
58
|
})
|
|
60
59
|
|
|
61
60
|
yield* node
|
|
62
61
|
.addEdge({ target: 'ws', edgeChannel: edgeChannel.webChannel, replaceIfExists: true })
|
|
63
62
|
.pipe(Effect.acquireRelease(() => node.removeEdge('ws').pipe(Effect.orDie)))
|
|
64
63
|
|
|
65
|
-
yield*
|
|
64
|
+
yield* edgeChannel.webChannel.closedDeferred
|
|
66
65
|
}).pipe(Effect.scoped, Effect.forever, Effect.interruptible, Effect.provide(binaryWebSocketConstructorLayer))
|
|
67
66
|
|
|
68
67
|
const binaryWebSocketConstructorLayer = Layer.succeed(Socket.WebSocketConstructor, (url, protocols) => {
|
|
@@ -74,9 +73,11 @@ const binaryWebSocketConstructorLayer = Layer.succeed(Socket.WebSocketConstructo
|
|
|
74
73
|
export const makeWebSocketEdge = ({
|
|
75
74
|
socket,
|
|
76
75
|
socketType,
|
|
76
|
+
debug: debugInfo,
|
|
77
77
|
}: {
|
|
78
78
|
socket: Socket.Socket
|
|
79
79
|
socketType: SocketType
|
|
80
|
+
debug?: { id?: string }
|
|
80
81
|
}): Effect.Effect<
|
|
81
82
|
{
|
|
82
83
|
webChannel: WebChannel.WebChannel<typeof WebmeshSchema.Packet.Type, typeof WebmeshSchema.Packet.Type>
|
|
@@ -99,7 +100,7 @@ export const makeWebSocketEdge = ({
|
|
|
99
100
|
|
|
100
101
|
const closedDeferred = yield* Deferred.make<void>().pipe(Effect.acquireRelease(Deferred.done(Exit.void)))
|
|
101
102
|
|
|
102
|
-
const retryOpenTimeoutSchedule = Schedule.exponential(100).pipe(
|
|
103
|
+
const retryOpenTimeoutSchedule = Schedule.union(Schedule.exponential(100), Schedule.spaced(5000)).pipe(
|
|
103
104
|
Schedule.whileInput((_: Socket.SocketError) => _.reason === 'OpenTimeout' || _.reason === 'Open'),
|
|
104
105
|
)
|
|
105
106
|
|
|
@@ -107,13 +108,13 @@ export const makeWebSocketEdge = ({
|
|
|
107
108
|
Stream.pipeThroughChannel(Socket.toChannel(socket)),
|
|
108
109
|
Stream.catchTag(
|
|
109
110
|
'SocketError',
|
|
110
|
-
Effect.
|
|
111
|
-
// yield* Effect.logError(`[websocket-edge] Socket error`, error)
|
|
111
|
+
Effect.fnUntraced(function* (error) {
|
|
112
|
+
// yield* Effect.logError(`[websocket-edge] Socket error`, error, { socketType, debugId: debugInfo?.id })
|
|
112
113
|
// In the case of the socket being closed, we're interrupting the stream
|
|
113
114
|
// and close the WebChannel (which can be observed from the outside)
|
|
114
115
|
if (error.reason === 'Close') {
|
|
115
|
-
yield* isConnectedLatch.close
|
|
116
116
|
yield* Deferred.succeed(closedDeferred, undefined)
|
|
117
|
+
yield* isConnectedLatch.close
|
|
117
118
|
return yield* Effect.interrupt
|
|
118
119
|
} else {
|
|
119
120
|
return yield* Effect.fail(error)
|
|
@@ -134,6 +135,12 @@ export const makeWebSocketEdge = ({
|
|
|
134
135
|
}),
|
|
135
136
|
),
|
|
136
137
|
Stream.runDrain,
|
|
138
|
+
Effect.tap(
|
|
139
|
+
Effect.fnUntraced(function* () {
|
|
140
|
+
yield* Deferred.succeed(closedDeferred, undefined)
|
|
141
|
+
yield* isConnectedLatch.close
|
|
142
|
+
}),
|
|
143
|
+
),
|
|
137
144
|
Effect.interruptible,
|
|
138
145
|
Effect.withSpan('makeWebSocketEdge:listen'),
|
|
139
146
|
Effect.tapCauseLogPretty,
|