forked from angular/in-memory-web-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelay-response.js
27 lines (27 loc) · 1.01 KB
/
delay-response.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Observable } from 'rxjs';
// Replaces use of RxJS delay. See v0.5.4.
/** adds specified delay (in ms) to both next and error channels of the response observable */
export function delayResponse(response$, delayMs) {
return new Observable(function (observer) {
var completePending = false;
var nextPending = false;
var subscription = response$.subscribe(function (value) {
nextPending = true;
setTimeout(function () {
observer.next(value);
if (completePending) {
observer.complete();
}
}, delayMs);
}, function (error) { return setTimeout(function () { return observer.error(error); }, delayMs); }, function () {
completePending = true;
if (!nextPending) {
observer.complete();
}
});
return function () {
return subscription.unsubscribe();
};
});
}
//# sourceMappingURL=delay-response.js.map