@xylabs/threads
Version:
Web workers & worker threads as simple as a function call
8 lines (7 loc) • 2.37 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/observable.ts"],
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { ObservableLike, SubscriptionObserver } from 'observable-fns'\nimport { Observable } from 'observable-fns'\n\nconst $observers = Symbol('observers')\n\n/**\n * Observable subject. Implements the Observable interface, but also exposes\n * the `next()`, `error()`, `complete()` methods to initiate observable\n * updates \"from the outside\".\n *\n * Use `Observable.from(subject)` to derive an observable that proxies all\n * values, errors and the completion raised on this subject, but does not\n * expose the `next()`, `error()`, `complete()` methods.\n */\nexport class Subject<T> extends Observable<T> implements ObservableLike<T> {\n private [$observers]: SubscriptionObserver<T>[]\n\n constructor() {\n super((observer) => {\n this[$observers] = [...(this[$observers] ?? []), observer]\n const unsubscribe = () => {\n this[$observers] = this[$observers].filter(someObserver => someObserver !== observer)\n }\n return unsubscribe\n })\n\n this[$observers] = []\n }\n\n /** Signal completion to all subscribers. */\n complete() {\n for (const observer of this[$observers]) observer.complete()\n }\n\n /** Signal an error to all subscribers. */\n error(error: any) {\n for (const observer of this[$observers]) observer.error(error)\n }\n\n /** Emit a new value to all subscribers. */\n next(value: T) {\n for (const observer of this[$observers]) observer.next(value)\n }\n}\n\n/** Re-export of the Observable class from the `observable-fns` library. */\nexport { Observable } from 'observable-fns'\n"],
"mappings": ";AAEA,SAAS,kBAAkB;AA6C3B,SAAS,cAAAA,mBAAkB;AA3C3B,IAAM,aAAa,uBAAO,WAAW;AAW9B,IAAM,UAAN,cAAyB,WAA2C;AAAA,EACzE,CAAS,UAAU;AAAA,EAEnB,cAAc;AACZ,UAAM,CAAC,aAAa;AAClB,WAAK,UAAU,IAAI,CAAC,GAAI,KAAK,UAAU,KAAK,CAAC,GAAI,QAAQ;AACzD,YAAM,cAAc,MAAM;AACxB,aAAK,UAAU,IAAI,KAAK,UAAU,EAAE,OAAO,kBAAgB,iBAAiB,QAAQ;AAAA,MACtF;AACA,aAAO;AAAA,IACT,CAAC;AAED,SAAK,UAAU,IAAI,CAAC;AAAA,EACtB;AAAA;AAAA,EAGA,WAAW;AACT,eAAW,YAAY,KAAK,UAAU,EAAG,UAAS,SAAS;AAAA,EAC7D;AAAA;AAAA,EAGA,MAAM,OAAY;AAChB,eAAW,YAAY,KAAK,UAAU,EAAG,UAAS,MAAM,KAAK;AAAA,EAC/D;AAAA;AAAA,EAGA,KAAK,OAAU;AACb,eAAW,YAAY,KAAK,UAAU,EAAG,UAAS,KAAK,KAAK;AAAA,EAC9D;AACF;",
"names": ["Observable"]
}