wspromisify 2.9.0 → 2.9.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.
- package/package.json +1 -1
- package/src/WSC.ts +5 -5
- package/test/specs/stream-real.ts +1 -3
package/package.json
CHANGED
package/src/WSC.ts
CHANGED
|
@@ -10,6 +10,7 @@ const zipnum = new Zipnum()
|
|
|
10
10
|
const callit = callWith([])
|
|
11
11
|
const isNumber = both(typeIs('Number'), notf(isNaN))
|
|
12
12
|
const ping_send_opts: wsc.SendOptions = {_is_ping: true}
|
|
13
|
+
const clearTO = (to: NodeJS.Timeout|null) => to && clearTimeout(to)
|
|
13
14
|
|
|
14
15
|
type EventHandler<T extends keyof WebSocketEventMap> = AnyFunc<any, [WebSocketEventMap[T]]>
|
|
15
16
|
type EventHandlers = {
|
|
@@ -284,7 +285,7 @@ class WebSocketClient {
|
|
|
284
285
|
data_type: config.data_type,
|
|
285
286
|
sent_time: config.timer ? Date.now() : null,
|
|
286
287
|
ff(x: any) {
|
|
287
|
-
|
|
288
|
+
clearTO(to)
|
|
288
289
|
ff(x)
|
|
289
290
|
}
|
|
290
291
|
}
|
|
@@ -301,16 +302,15 @@ class WebSocketClient {
|
|
|
301
302
|
queue[message_id] = {
|
|
302
303
|
msg,
|
|
303
304
|
ff: (msg: ResponseDataType&{done?: boolean}) => {
|
|
304
|
-
if(to) {clearTimeout(to); to=null}
|
|
305
|
-
if(msg?.done) { cleanup(); done=true }
|
|
306
305
|
fulfill(msg)
|
|
306
|
+
if(msg?.done) { cleanup(); done=true }
|
|
307
307
|
},
|
|
308
308
|
data_type: config.data_type,
|
|
309
309
|
sent_time: config.timer ? Date.now() : null
|
|
310
310
|
}
|
|
311
311
|
while(!done) yield await new Promise<ResponseDataType>((ff, rj) => {
|
|
312
|
-
to =
|
|
313
|
-
})
|
|
312
|
+
clearTO(to), to=timeout(rj), fulfill=ff
|
|
313
|
+
}).finally(() => {clearTO(to), to=null})
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
// TODO: Add .on handlers to config!
|
|
@@ -26,9 +26,7 @@ test('stream-real', timeout(1.5e4, () => new Promise<void>(async (ff, rj) => {
|
|
|
26
26
|
const stream = ws.stream<typeof streamMsg, any>(streamMsg)
|
|
27
27
|
const chunks: any[] = []
|
|
28
28
|
|
|
29
|
-
for await (const chunk of stream)
|
|
30
|
-
chunks.push(chunk)
|
|
31
|
-
}
|
|
29
|
+
for await (const chunk of stream) chunks.push(chunk)
|
|
32
30
|
|
|
33
31
|
clearTimeout(to)
|
|
34
32
|
|