import { checkObservable } from "../_check" import { NOOP_SUBSCRIBER, Source } from "../_core" import { In, Out } from "../_interfaces" import { makeObservable } from "../_obs" import { Transaction } from "../_tx" import { curry2 } from "../_util" import { dispatcherOf, Observable } from "../Observable" import { Pipe, PipeSubscriber } from "./_base" import { JoinOperator } from "./_join" import { SVSource } from "./sample" import { toEventStream } from "./toEventStream" export const skipUntil: CurriedSkipUntil = curry2(_skipUntil) export interface CurriedSkipUntil { (trigger: Observable, observable: In): Out< ObsType, ValueType > (trigger: Observable): ( observable: In, ) => Out } function _skipUntil(trigger: Observable, observable: Observable): Observable { checkObservable(trigger) return makeObservable( observable, new SkipUntil(dispatcherOf(toEventStream(trigger)), dispatcherOf(observable)), ) } class SkipUntil extends JoinOperator implements PipeSubscriber { protected source!: SVSource private pass: boolean = false constructor(vSrc: Source, sSrc: Source) { super(new SVSource(vSrc, sSrc, NOOP_SUBSCRIBER)) this.source.vDest = new Pipe(this) } public next(tx: Transaction, val: T): void { this.forkNext(tx, val) } public joinNext(tx: Transaction, val: T): void { this.pass && this.sink.next(tx, val) } public pipedNext(sender: Pipe, tx: Transaction, v: any): void { this.pass = true this.source.disposeValue() } public pipedError(sender: Pipe, tx: Transaction, err: Error): void { // trigger errors are ignored } public pipedEnd(sender: Pipe, tx: Transaction): void { this.source.disposeValue() } }