braid-http 1.3.13 → 1.3.15

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/LICENSE.txt ADDED
@@ -0,0 +1,11 @@
1
+ Invisible Property License
2
+
3
+ 1. You have the right to use this IP for any purpose.
4
+ 2. If you make profit, you agree to give back a fair share of the profit to
5
+ the creators of this IP.
6
+ 3. The creators will tell you how much they think is a fair share, if your
7
+ usage matters to them, and promise not to take you to court to enforce
8
+ the agreement.
9
+
10
+ (In other words, this license thus runs on the honor system. You are invited
11
+ to participate in our community with honor.)
@@ -222,10 +222,11 @@ async function braid_fetch (url, params = {}) {
222
222
  () => underlying_aborter.abort()
223
223
  )
224
224
 
225
- var waitTime = 10
225
+ var waitTime = 1
226
226
  var res = null
227
227
  var subscription_cb = null
228
228
  var subscription_error = null
229
+ var cb_running = false
229
230
 
230
231
  return await new Promise((done, fail) => {
231
232
  connect()
@@ -233,16 +234,20 @@ async function braid_fetch (url, params = {}) {
233
234
  let on_error = e => {
234
235
  on_error = () => {}
235
236
 
236
- if (!params.retry || e.name === "AbortError" || e.startsWith?.('Parse error in headers')) {
237
+ if (!params.retry ||
238
+ e.name === "AbortError" ||
239
+ e.startsWith?.('Parse error in headers') ||
240
+ cb_running) {
241
+
237
242
  subscription_error?.(e)
238
243
  return fail(e)
239
244
  }
240
245
 
241
246
  underlying_aborter.abort()
242
247
 
243
- console.log(`retrying in ${waitTime}ms: ${url} after error: ${e}`)
244
- setTimeout(connect, waitTime)
245
- waitTime = Math.min(waitTime * 2, 3000)
248
+ console.log(`retrying in ${waitTime}s: ${url} after error: ${e}`)
249
+ setTimeout(connect, waitTime * 1000)
250
+ waitTime = Math.min(waitTime + 1, 3)
246
251
  }
247
252
 
248
253
  try {
@@ -313,7 +318,9 @@ async function braid_fetch (url, params = {}) {
313
318
  if (original_signal?.aborted) throw new DOMException('already aborted', 'AbortError')
314
319
 
315
320
  // Yay! We got a new version! Tell the callback!
321
+ cb_running = true
316
322
  cb(result)
323
+ cb_running = false
317
324
  } else
318
325
  // This error handling code runs if the connection
319
326
  // closes, or if there is unparseable stuff in the
@@ -399,7 +406,7 @@ async function braid_fetch (url, params = {}) {
399
406
  done(res)
400
407
 
401
408
  params?.retry?.onRes?.(res)
402
- waitTime = 10
409
+ waitTime = 1
403
410
  } catch (e) { on_error(e) }
404
411
  }
405
412
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-http",
3
- "version": "1.3.13",
3
+ "version": "1.3.15",
4
4
  "description": "An implementation of Braid-HTTP for Node.js and Browsers",
5
5
  "scripts": {
6
6
  "test": "node test/server.js"