import { Destroyable } from "base/Destroyable"; import { Message } from "base/Message"; import { MessageType } from "types/MessageType"; type ExecutorApplier = (executor: (v: T) => void) => (v: T) => void; /** * Applies a value transfer function to the resolver * and returns the same value transfer function for the resolver * Useful for applying functions like debounced or throttle */ export function ExecutorApplied( $base: MessageType, applier: ExecutorApplier, ) { return Message(function ExecutorAppliedImpl(resolve, reject) { $base.catch(reject); const sub = Destroyable($base.then(applier(resolve))); return function executorAppliedDestroy() { sub.destroy(); }; }); }