multitude
Version:
Comprehensive streams for push and pull
9 lines • 445 B
JavaScript
import { Handler } from "../../helpers/index.js";
import { isSubscriptionLike } from "./type-guards.js";
import { TypeGuard } from 'type-core';
export function teardown(teardown) {
if (TypeGuard.isFunction(teardown)) return teardown;
if (TypeGuard.isEmpty(teardown)) return Handler.noop;
if (isSubscriptionLike(teardown)) return () => teardown.unsubscribe();
throw new TypeError('Expected teardown to be a function or a subscription');
}