@nxtedition/lib 14.1.20 → 14.2.0
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/rxjs/firstValueFrom.js +2 -4
- package/rxjs/withAbortSignal.js +29 -0
package/package.json
CHANGED
package/rxjs/firstValueFrom.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const rxjs = require('rxjs')
|
|
2
1
|
const rx = require('rxjs/operators')
|
|
3
|
-
const
|
|
2
|
+
const withAbortSignal = require('./withAbortSignal')
|
|
4
3
|
|
|
5
4
|
module.exports = function firstValueFrom(x$, config) {
|
|
6
5
|
const hasConfig = config && typeof config === 'object'
|
|
@@ -8,8 +7,7 @@ module.exports = function firstValueFrom(x$, config) {
|
|
|
8
7
|
const timeout = hasConfig ? config.timeout : undefined
|
|
9
8
|
|
|
10
9
|
if (signal) {
|
|
11
|
-
x$ =
|
|
12
|
-
x$ = x$.pipe(rx.throwIfEmpty(() => new AbortError()))
|
|
10
|
+
x$ = x$.pipe(withAbortSignal(signal))
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
if (timeout) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const rxjs = require('rxjs')
|
|
2
|
+
const { AbortError } = require('../errors')
|
|
3
|
+
|
|
4
|
+
function withAbortSignal(signal) {
|
|
5
|
+
return new rxjs.Observable((o) => {
|
|
6
|
+
o.add(this.subscribe(o))
|
|
7
|
+
|
|
8
|
+
if (!signal) {
|
|
9
|
+
return
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const onAbort = () => {
|
|
13
|
+
o.error(signal.reason ?? new AbortError())
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (signal.aborted) {
|
|
17
|
+
onAbort()
|
|
18
|
+
} else {
|
|
19
|
+
signal.addEventListener('abort', onAbort)
|
|
20
|
+
o.add(() => {
|
|
21
|
+
signal.removeEventListener('abort', onAbort)
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
rxjs.Observable.prototype.withAbortSignal = withAbortSignal
|
|
28
|
+
|
|
29
|
+
module.exports = (signal) => (o) => withAbortSignal.call(o, signal)
|