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 CHANGED
@@ -41,7 +41,7 @@
41
41
  "prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
42
42
  "all": "npm run dev && npm run prod"
43
43
  },
44
- "version": "2.9.0",
44
+ "version": "2.9.1",
45
45
  "type": "module",
46
46
  "exports": {
47
47
  ".": {
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
- clearTimeout(to)
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 = timeout(rj), fulfill=ff
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