@superhero/eventflow-spoke 4.0.4 → 4.0.5
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/index.js +44 -15
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -284,27 +284,56 @@ export default class Spoke
|
|
|
284
284
|
|
|
285
285
|
return new Promise(async (accept, reject) =>
|
|
286
286
|
{
|
|
287
|
-
const
|
|
287
|
+
const timeoutId = setTimeout(() =>
|
|
288
288
|
{
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
289
|
+
unsubscribe().catch(reject).then(() =>
|
|
290
|
+
{
|
|
291
|
+
const error = new Error(`wait timed out (${timeout}) for ${domain} › ${pid} › ${eventNames.join(' | ')}`)
|
|
292
|
+
error.code = 'E_EVENTFLOW_WAIT_TIMEOUT'
|
|
293
|
+
reject(error)
|
|
294
|
+
})
|
|
292
295
|
}, timeout)
|
|
293
296
|
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
if(event.pid === pid)
|
|
297
|
+
const
|
|
298
|
+
unsubscribe = async () =>
|
|
297
299
|
{
|
|
298
|
-
|
|
299
|
-
.
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
300
|
+
const
|
|
301
|
+
unsubscribers = eventNames.map((name) => this.unsubscribe(domain, name, subscriber)),
|
|
302
|
+
results = await Promise.allSettled(unsubscribers),
|
|
303
|
+
rejections = results.filter((result) => 'rejected' === result.status)
|
|
304
|
+
|
|
305
|
+
if(rejections.length)
|
|
306
|
+
{
|
|
307
|
+
const error = new Error(`unsubscribe failed: ${domain} › ${pid} › ${eventNames.join(' | ')}`)
|
|
308
|
+
error.code = 'E_EVENTFLOW_WAIT_UNSUBSCRIBE_FAILED'
|
|
309
|
+
error.cause = rejections.map((result) => result.reason)
|
|
310
|
+
throw error
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
subscriber = async (event) =>
|
|
314
|
+
{
|
|
315
|
+
if(event.pid === pid)
|
|
316
|
+
{
|
|
317
|
+
clearTimeout(timeoutId)
|
|
318
|
+
await unsubscribe().catch(reject)
|
|
319
|
+
accept(event)
|
|
320
|
+
}
|
|
304
321
|
}
|
|
305
|
-
}
|
|
306
322
|
|
|
307
|
-
|
|
323
|
+
const
|
|
324
|
+
subscribers = eventNames.map((name) => this.subscribe(domain, name, subscriber)),
|
|
325
|
+
results = await Promise.allSettled(subscribers),
|
|
326
|
+
rejections = results.filter((result) => 'rejected' === result.status)
|
|
327
|
+
|
|
328
|
+
if(rejections.length)
|
|
329
|
+
{
|
|
330
|
+
clearTimeout(timeoutId)
|
|
331
|
+
await unsubscribe().catch(reject)
|
|
332
|
+
const error = new Error(`subscribe failed: ${domain} › ${pid} › ${eventNames.join(' | ')}`)
|
|
333
|
+
error.code = 'E_EVENTFLOW_WAIT_SUBSCRIBE_FAILED'
|
|
334
|
+
error.cause = rejections.map((result) => result.reason)
|
|
335
|
+
reject(error)
|
|
336
|
+
}
|
|
308
337
|
})
|
|
309
338
|
}
|
|
310
339
|
|