Module sync

Source
Expand description

Synchronization utilities

Type Aliases§

Source§

type AnyFn = { ... }

Type for any function

Source§

type AwaitRet<T> = T extends (...args: any[]) => infer R ? Awaited<R> : never

Shorthand for Awaited<ReturnType>

Source§

type LatestUpdateArgsFn<TFn> = { ... }

Source§

type SerialCancelToken = "cancel"

The error type received by caller when an event is cancelled

Source§

type SerialEventCancelCallback = { ... }

The callback type passed to SerialEvent constructor to be called when the event is cancelled

Functions§

Source§

batch<TFn extends AnyFn>(
    args: BatchConstructor<TFn>,
): (...args: Parameters<TFn>) => Promise<AwaitRet<TFn>>

Factory for batched function. See BatchConstructor for usage.

Source§

debounce<TFn extends AnyFn>(
    args: DebounceConstructor<TFn>,
): (...args: Parameters<TFn>) => Promise<AwaitRet<TFn>>

Factory for debounced function. See DebounceConstructor for usage

Source§

latest<TFn extends AnyFn>(
    args: LatestConstructor<TFn>,
): (...args: Parameters<TFn>) => Promise<AwaitRet<TFn>>

Factory for latest. See LatestConstructor for usage.

Source§

makePromise<T>(): PromiseHandle<T>

Make a PromiseHandle with the promise object separate from its resolve and reject methods

Source§

once<TFn extends AnyFn>(
    args: OnceConstructor<TFn>,
): (...args: Parameters<TFn>) => Promise<AwaitRet<TFn>>

Factory function for once. See OnceConstructor for usage

Source§

scopedCapture<T>(fn: () => Promise<T>, obj: unknown): Promise<T>

Execute an async closure fn, and guarantee that obj will not be garbage-collected, until the promise is resolved.

Source§

scopedCaptureSync<T>(fn: () => T, obj: unknown): T

Execute a closure fn, and guarantee that obj will not be garbage-collected during the execution

Source§

serial<TFn extends AnyFn>(
    args: SerialConstructor<TFn>,
): (
    ...args: Parameters<TFn>,
) => Promise<Result<Awaited<ReturnType<TFn>>, "cancel">>

Factory function for serial. See SerialConstructor for usage

Classes§

RwLock

Ensure you have exclusive access in concurrent code

Interfaces§

BatchConstructor

Options to construct a batch function

DebounceConstructor

Options for debounce function

LatestConstructor

Args for constructing latest

OnceConstructor

Args for constructing a once

PromiseHandle

A handle of the promise that breaks down the promise object and its resolve and reject functions

SerialConstructor

Options for serial function