Socket
Socket
Sign inDemoInstall

@dxos/async

Package Overview
Dependencies
Maintainers
13
Versions
2963
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dxos/async

Basic async utils


Version published
Weekly downloads
2.5K
decreased by-56.99%
Maintainers
13
Weekly downloads
 
Created
Source

Async

Build Status Coverage Status Greenkeeper badge js-semistandard-style standard-readme compliant

Install

$ npm install @dxos/async

Usage

import async from '@dxos/async';

const test = async () => {
  const [getValue, setValue] = trigger();
  
  setTimeout(() => {
    setValue(100);
  }, 1000);

  const value = await getValue();
  expect(value).toBe(100);
};

API

export function noop(...args: any[]): any[];
export function sleep(timeout: any): Promise<unknown>;
export function timeout(f: any, timeout?: number | undefined): Promise<unknown>;
export function promiseTimeout(promise: Promise<any>, timeout: number): Promise<unknown>;
export function waitForCondition(condFn: Function, timeout?: number | undefined, interval?: number | undefined): any;

export function onEvent(eventEmitter: any, eventName: string, callback: Function): () => any;
export function addListener(eventEmitter: any, eventName: any, callback: any): {
    remove: () => any;
};
export function waitForEvent(eventEmitter: any, eventName: string, test?: Function | undefined, timeout?: number | undefined): Promise<unknown>;

export function expectToThrow(test: Function, errType?: ErrorConstructor): Promise<void>;

export class Event<T> {}

/**
 * Returns a tuple containing a Promise that will be resolved when the resolver function is called.
 */
export function trigger(timeout?: number): [() => Promise<void>, () => void];
export function trigger<T>(timeout?: number): [() => Promise<T>, (arg: T) => void];

/**
 * Use `trigger` instead.
 * @deprecated
 */
export const useValue: typeof trigger;

/**
 * Multiple-use version of `trigger`.
 *
 * Has two states:
 * - WAITING: promise is in pending state and will be resolved once `wake()` is called.
 * - READY: promise is already resolved, and all calls to `wait()` resolve immedeately.
 *
 * Trigger starts in WAITING state initially.
 * Use `reset()` to swith resolved trigger back to WAITING state.
 */
export declare class Trigger {}

/**
 * Returns a callback and a promise that's resolved when the callback is called n times.
 * @param n The number of times the callback is required to be called to resolve the promise.
 */
export declare const latch: (n?: number) => readonly [Promise<number>, () => void];

/**
 * Waits for the specified number of events from the given emitter.
 */
export declare const sink: (emitter: EventEmitter, event: string, count?: number) => Promise<void>;

Contributing

PRs accepted.

License

GPL-3.0 © DxOS

FAQs

Package last updated on 20 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc