@toruslabs/broadcast-channel
Version:
A BroadcastChannel that works in New Browsers, Old Browsers, WebWorkers
25 lines (24 loc) • 1.15 kB
TypeScript
import loglevel from "loglevel";
/**
* returns true if the given object is a promise
*/
export declare function isPromise(obj: unknown): boolean;
export declare const PROMISE_RESOLVED_FALSE: Promise<boolean>;
export declare const PROMISE_RESOLVED_TRUE: Promise<boolean>;
export declare const PROMISE_RESOLVED_VOID: Promise<void>;
export declare function sleep<T>(time?: number, resolveWith?: T): Promise<T>;
export declare function randomInt(min: number, max: number): number;
/**
* https://stackoverflow.com/a/8084248
*/
export declare function generateRandomId(): string;
/**
* returns the current time in micro-seconds,
* WARNING: This is a pseudo-function
* Performance.now is not reliable in webworkers, so we just make sure to never return the same time.
* This is enough in browsers, and this function will not be used in nodejs.
* The main reason for this hack is to ensure that BroadcastChannel behaves equal to production when it is used in fast-running unit tests.
*/
export declare function microSeconds(): number;
export declare const log: loglevel.Logger;
export declare const setLogLevel: (level: loglevel.LogLevelDesc) => void;