Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prodo-ai/js-async

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prodo-ai/js-async

JS utilities for async/await

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
3
Weekly downloads
 
Created
Source

JS ASync

Utility library for handling async/await.

Usage

denodeify

Turns a function that accepts a node-style callback into one that returns a Promise:

import {denodeify} from "@prodo-ai/js-async";

const nodeStyleFunction = (arg1, arg2, callback) => {
  if (arg1 == null) {
    callback(new Error("Must specify `arg1`."));
  }
  callback(null, arg1 + arg2);
}

const asyncFunction = denodeify(nodeStyleFunction);

asyncFunction(1, 2)
  .then(console.log)
  .catch(console.error);

fromCallback

The same as denodeify, but without error handling. Probably don't use this.

keepTrying

Keeps attempting a behaviour until it succeeds:

import {keepTrying} from "@prodo-ai/js-async";

const result = await keepTrying({
  behaviour: () => service.getResult()
});

You can also pass additional parameters for greater control:

  • until - a predicate that can be used to determine success. By default, this predicate just checks if the result is non-null.
  • ignoreErrors - if false, gives up trying after an error is thrown.
  • timeout - a timeout, after which an Error is thrown.
  • inbetweenAttempts - a callback that is executed between each attempt.

waitUntil

Waits until a predicate passes:

import {waitUntil} from "@prodo-ai/js-async";
import {duration, SECOND} from "@prodo-ai/js-timing";

waitUntil({
  condition: async () => (await service.getStatus()) === "OK",
  pauseTime: duration(1, SECOND),
}).then(service.getResult);

You can also pass additional parameters for greater control:

  • timeout - a timeout, after which an Error is thrown.

Information

Owner: Prodo Tech Ltd

Maintainer: tdawes

License: UNLICENSED (for now)

FAQs

Package last updated on 06 Aug 2018

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