Mirror: 🎩 A tiny but capable push & pull stream library for TypeScript and Flow
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix skipUntil pulling and add early closing (#54)

* Rename gotSignal to pulled in skipUntil

* Fix pulling behaviour of skipUntil

* Close source when notifier will never emit

When the notifier ends before it emits any value
it's safe to close the source as it can never emit
any values anymore.

* Fix active pushing

Pull from notifier source on start so it has a chance
to send a value before the source pushes its first value.

authored by kitten.sh and committed by

GitHub 55cf86af c6c30510

+30 -24
+26 -21
src/wonka_operators.re
··· 635 635 ); 636 636 637 637 type skipUntilStateT = { 638 - mutable skip: bool, 639 - mutable ended: bool, 640 - mutable gotSignal: bool, 641 638 mutable sourceTalkback: (. talkbackT) => unit, 642 639 mutable notifierTalkback: (. talkbackT) => unit, 640 + mutable skip: bool, 641 + mutable pulled: bool, 642 + mutable ended: bool, 643 643 }; 644 644 645 645 [@genType] ··· 647 647 curry(source => 648 648 curry(sink => { 649 649 let state: skipUntilStateT = { 650 - skip: true, 651 - ended: false, 652 - gotSignal: false, 653 650 sourceTalkback: talkbackPlaceholder, 654 651 notifierTalkback: talkbackPlaceholder, 652 + skip: true, 653 + pulled: false, 654 + ended: false, 655 655 }; 656 656 657 657 source((. signal) => ··· 664 664 | Start(innerTb) => 665 665 state.notifierTalkback = innerTb; 666 666 innerTb(. Pull); 667 - tb(. Pull); 668 667 | Push(_) => 669 668 state.skip = false; 670 669 state.notifierTalkback(. Close); 670 + | End when state.skip => 671 + state.ended = true; 672 + state.sourceTalkback(. Close); 671 673 | End => () 672 674 } 673 675 ); 674 - | Push(_) when state.skip && !state.ended => 675 - state.sourceTalkback(. Pull) 676 - | Push(_) when !state.ended => 677 - state.gotSignal = false; 676 + | Push(_) when !state.skip && !state.ended => 677 + state.pulled = false; 678 678 sink(. signal); 679 679 | Push(_) => () 680 680 | End => ··· 689 689 sink(. 690 690 Start( 691 691 (. signal) => 692 - switch (signal) { 693 - | Close => 694 - if (state.skip) { 695 - state.notifierTalkback(. Close); 692 + if (!state.ended) { 693 + switch (signal) { 694 + | Close => 695 + state.ended = true; 696 + state.sourceTalkback(. Close); 697 + if (state.skip) { 698 + state.notifierTalkback(. Close); 699 + }; 700 + | Pull when !state.pulled => 701 + state.pulled = true; 702 + if (state.skip) { 703 + state.notifierTalkback(. Pull); 704 + }; 705 + state.sourceTalkback(. Pull); 706 + | Pull => () 696 707 }; 697 - state.ended = true; 698 - state.sourceTalkback(. Close); 699 - | Pull when !state.gotSignal && !state.ended => 700 - state.gotSignal = true; 701 - state.sourceTalkback(. Pull); 702 - | Pull => () 703 708 }, 704 709 ), 705 710 );
+4 -3
src/wonka_operators.test.ts
··· 804 804 805 805 describe('skipUntil', () => { 806 806 const noop = operators.skipUntil(sources.fromValue(null)); 807 - // TODO: passesPassivePull(noop); 808 - // TODO: passesActivePush(noop); 809 - // TODO: passesSinkClose(noop); 807 + passesPassivePull(noop); 808 + passesActivePush(noop); 809 + passesSinkClose(noop); 810 810 passesSourceEnd(noop); 811 811 passesSingleStart(noop); 812 812 passesAsyncSequence(noop); 813 + passesStrictEnd(noop); 813 814 814 815 it('skips values until the notifier source emits', () => { 815 816 const { source: notifier$, next: notify } = sources.makeSubject();