UNPKG

@lifaon/rx-js-light

Version:

Blazing fast Observables

28 lines (27 loc) 712 B
import {asyncUnsubscribe} from "../../../../../../misc/helpers/async-unsubscribe.mjs"; import {empty} from "../../../../../built-in/from/without-notifications/values/empty/empty.mjs"; export function takeObservable(subscribe, count) { if (count <= 0) { return empty(); } else { return emit => { let running = true; const unsubscribe = subscribe(value => { if (running) { --count; if (count === 0) { running = false; asyncUnsubscribe(() => unsubscribe); } emit(value); } }); return () => { if (running) { running = false; unsubscribe(); } }; }; } }