braid-http 1.3.15 → 1.3.16

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.
@@ -64,16 +64,19 @@ function braidify_http (http) {
64
64
  on_update = f
65
65
 
66
66
  // And set up a subscription parser
67
- var parser = subscription_parser((update, error) => {
67
+ var parser = subscription_parser(async (update, error) => {
68
68
  if (!error)
69
- on_update && on_update(update)
69
+ on_update && (await on_update(update))
70
70
  else
71
71
  on_error && on_error(error)
72
72
  })
73
73
 
74
74
  // That will run each time we get new data
75
+ var chain = Promise.resolve()
75
76
  res.orig_on('data', (chunk) => {
76
- parser.read(chunk)
77
+ chain = chain.then(async () => {
78
+ await parser.read(chunk)
79
+ })
77
80
  })
78
81
  }
79
82
 
@@ -312,14 +315,14 @@ async function braid_fetch (url, params = {}) {
312
315
 
313
316
  // Each time something happens, we'll either get a new
314
317
  // version back, or an error.
315
- (result, err) => {
318
+ async (result, err) => {
316
319
  if (!err) {
317
320
  // check whether we aborted
318
321
  if (original_signal?.aborted) throw new DOMException('already aborted', 'AbortError')
319
322
 
320
323
  // Yay! We got a new version! Tell the callback!
321
324
  cb_running = true
322
- cb(result)
325
+ await cb(result)
323
326
  cb_running = false
324
327
  } else
325
328
  // This error handling code runs if the connection
@@ -426,21 +429,21 @@ async function handle_fetch_stream (stream, cb, on_bytes) {
426
429
  var {done, value} = await reader.read()
427
430
  }
428
431
  catch (e) {
429
- cb(null, e)
432
+ await cb(null, e)
430
433
  return
431
434
  }
432
435
 
433
436
  // Check if this connection has been closed!
434
437
  if (done) {
435
438
  console.debug("Connection closed.")
436
- cb(null, 'Connection closed')
439
+ await cb(null, 'Connection closed')
437
440
  return
438
441
  }
439
442
 
440
443
  on_bytes?.(value)
441
444
 
442
445
  // Tell the parser to process some more stream
443
- parser.read(value)
446
+ await parser.read(value)
444
447
  }
445
448
  }
446
449
 
@@ -459,7 +462,7 @@ var subscription_parser = (cb) => ({
459
462
 
460
463
  // You give it new input information as soon as you get it, and it will
461
464
  // report back with new versions as soon as it finds them.
462
- read (input) {
465
+ async read (input) {
463
466
 
464
467
  // Store the new input!
465
468
  for (let x of input) this.state.input.push(x)
@@ -471,7 +474,7 @@ var subscription_parser = (cb) => ({
471
474
  try {
472
475
  this.state = parse_update (this.state)
473
476
  } catch (e) {
474
- this.cb(null, e)
477
+ await this.cb(null, e)
475
478
  return
476
479
  }
477
480
 
@@ -503,9 +506,9 @@ var subscription_parser = (cb) => ({
503
506
  }
504
507
 
505
508
  try {
506
- this.cb(update)
509
+ await this.cb(update)
507
510
  } catch (e) {
508
- this.cb(null, e)
511
+ await this.cb(null, e)
509
512
  return
510
513
  }
511
514
 
@@ -515,7 +518,7 @@ var subscription_parser = (cb) => ({
515
518
 
516
519
  // Or maybe there's an error to report upstream
517
520
  else if (this.state.result === 'error') {
518
- this.cb(null, this.state.message)
521
+ await this.cb(null, this.state.message)
519
522
  return
520
523
  }
521
524
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.15",
3
+ "version": "1.3.16",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"