All Projects → blend → Promise Utils

blend / Promise Utils

Licence: mit
Lodash-like, dependency-free utilities for native ES6 promises.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Promise Utils

Javascript-Interview-Preparation
A curated collection of javascript interview questions & solutions.
Stars: ✭ 163 (-39.18%)
Mutual labels:  promises, lodash
absurdum
The Ridiculous Application of Reduce
Stars: ✭ 61 (-77.24%)
Mutual labels:  lodash
underwater
~2kb - ES6 Collection of helper functions. Lodash like
Stars: ✭ 18 (-93.28%)
Mutual labels:  lodash
underscore.haz
🔍 _.haz() is like _.has() but this underscore and/or lodash mixin lets you do deep object key existence checking with a dot denoted string, for example 'a.b.c'
Stars: ✭ 13 (-95.15%)
Mutual labels:  lodash
queueable
Convert streams to async ⌛ iterables ➰
Stars: ✭ 43 (-83.96%)
Mutual labels:  promises
fnbr.js
A library to interact with Epic Games' Fortnite HTTP and XMPP services
Stars: ✭ 73 (-72.76%)
Mutual labels:  promises
node-google-calendar
Simple node module that supports Google Calendar API
Stars: ✭ 76 (-71.64%)
Mutual labels:  promises
Zio
ZIO — A type-safe, composable library for async and concurrent programming in Scala
Stars: ✭ 3,167 (+1081.72%)
Mutual labels:  promises
await-mutex
Promised based Javascript Mutex
Stars: ✭ 36 (-86.57%)
Mutual labels:  promises
typedash
🚀 2KB lodash in typescript
Stars: ✭ 26 (-90.3%)
Mutual labels:  lodash
es-aux
JavaScript开发辅助,包含了开发过程中很多场景需要用到的函数。
Stars: ✭ 22 (-91.79%)
Mutual labels:  lodash
godash
Lodash for Golang
Stars: ✭ 43 (-83.96%)
Mutual labels:  lodash
spex
💡 Specialized Promise Extensions
Stars: ✭ 51 (-80.97%)
Mutual labels:  promises
eslint-plugin-lodash-template
ESLint plugin for John Resig-style micro template, Lodash's template, Underscore's template and EJS.
Stars: ✭ 15 (-94.4%)
Mutual labels:  lodash
queue-promises
Promises for Laravel queue jobs
Stars: ✭ 15 (-94.4%)
Mutual labels:  promises
apr
this is like caolan/async which is like lodash but async, but awaitful
Stars: ✭ 75 (-72.01%)
Mutual labels:  promises
react-wisteria
Managing the State with the Golden Path
Stars: ✭ 18 (-93.28%)
Mutual labels:  lodash
doasync
Promisify functions and objects immutably
Stars: ✭ 27 (-89.93%)
Mutual labels:  promises
Promise Pool
Map-like, concurrent promise processing
Stars: ✭ 258 (-3.73%)
Mutual labels:  promises
tall
Promise-based, No-dependency URL unshortner (expander) module for Node.js
Stars: ✭ 56 (-79.1%)
Mutual labels:  promises

promise-utils

Build Status Coverage Status Minzipped size

Promise-utils is a dependency-free JavaScript/TypeScript library that provides Lodash-like utility functions for dealing with native ES6 promises.

Installation

$ npm install blend-promise-utils

Usage Example

const promiseUtils = require('blend-promise-utils')
const { promises: fs } = require('fs')
const request = require('request-promise-native');
const isEmpty = require('lodash.isempty');

const MS_IN_SECOND = 1000;

async function main() {
  const cachedResponse = promiseUtils.memoize(
    async (contents) => request(contents.url),
    contents => contents.url,
    15 * MS_IN_SECOND // contents could change
  );

  const fileContents = await promiseUtils.map(
    ['file1', 'file2', 'file3'],
    async fileName => {
      const rawData = await fs.readFile(fileName);
      return JSON.parse(rawData);
    },
  );

  while (true) {
    await promiseUtils.delay(150); // avoid slamming CPU

    await promiseUtils.mapSeries(
      fileContents,
      async contents => {
        const remoteData = await cachedResponse(contents);

        const { results, errors } = await promiseUtils.settleAll([
          asyncFunction1(),
          asyncFunction2(),
          asyncFunction3(),
        ]);

        if (!isEmpty(errors)) {
          throw new Error(`Unable to settle all functions: ${JSON.stringify(errors)}`);
        } else {
          return results;
        }
      }
    )
  }

  await promiseUtils.retry(flakyFunction, { maxAttempts: 3, delayMs: 150 })(flakyFunctionArgument);

  await promiseUtils.timeout(longFunction, 60 * MS_IN_SECOND)(longFunctionArgument);
}

main()

API

Test

$ npm test

Documentation

Build docs

$ make docs

Push docs to Github

$ make push-docs

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].