Skip to content

Instantly share code, notes, and snippets.

View constb's full-sized avatar

Konstantin Bryzgalin constb

  • Antalya, Türkiye
  • 06:15 (UTC +03:00)
View GitHub Profile
@sashaaro
sashaaro / with-async-contenxt.operator.ts
Last active October 1, 2021 12:24
rxjs operator AsyncLocalStorage
import {AsyncLocalStorage} from "async_hooks";
import {MonoTypeOperatorFunction, Observable, Subscription} from "rxjs";
export function withinContext<T, S = any>(storage: AsyncLocalStorage<S>, store: () => S): MonoTypeOperatorFunction<T> {
return function (source: Observable<T>) {
return new Observable((observer) => {
let sub: Subscription;
storage.run(store(),() => {
sub = source.subscribe(observer);