-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
projects/s-rxjs-utils/src/lib/operators/delay-on-microtask-queue.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { fakeAsync, flushMicrotasks } from "@angular/core/testing"; | ||
import { Subject } from "rxjs"; | ||
import { expectSingleCallAndReset } from "s-ng-dev-utils"; | ||
import { | ||
testCompletionPropagation, | ||
testErrorPropagation, | ||
testUnsubscribePropagation, | ||
} from "../../test-helpers/misc-helpers"; | ||
import { delayOnMicrotaskQueue } from "./delay-on-microtask-queue"; | ||
|
||
describe("delayOnMicrotaskQueue()", () => { | ||
it("passes along values asynchronously", fakeAsync(() => { | ||
const source = new Subject<number>(); | ||
const spy = jasmine.createSpy(); | ||
source.pipe(delayOnMicrotaskQueue()).subscribe(spy); | ||
|
||
source.next(1); | ||
expect(spy).not.toHaveBeenCalled(); | ||
flushMicrotasks(); | ||
expectSingleCallAndReset(spy, 1); | ||
|
||
source.next(2); | ||
expect(spy).not.toHaveBeenCalled(); | ||
flushMicrotasks(); | ||
expectSingleCallAndReset(spy, 2); | ||
})); | ||
|
||
it( | ||
"passes along unsubscribes synchronously", | ||
testUnsubscribePropagation(delayOnMicrotaskQueue), | ||
); | ||
|
||
it( | ||
"passes along errors synchronously", | ||
testErrorPropagation(delayOnMicrotaskQueue), | ||
); | ||
|
||
it( | ||
"passes along completion synchronously", | ||
testCompletionPropagation(delayOnMicrotaskQueue), | ||
); | ||
}); |
9 changes: 9 additions & 0 deletions
9
projects/s-rxjs-utils/src/lib/operators/delay-on-microtask-queue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { asapScheduler } from "rxjs"; | ||
import { delay } from "rxjs/operators"; | ||
|
||
/** | ||
* Delays the emission of items from the source Observable using the microtask queue. | ||
*/ | ||
export function delayOnMicrotaskQueue() { | ||
return delay(0, asapScheduler); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters