2.2.5 • Published 6 years ago

cf-util-async v2.2.5

Weekly downloads
67
License
BSD-3-Clause
Repository
-
Last release
6 years ago

cf-util-async

Cloudflare Async Util

Installation

$ npm install cf-util-async

Usage

Running async functions in a series:

import http from 'cf-util-http';
import {series} from 'cf-util-async';

series([
  cb => http.get('endpoint-1.json', null, cb), // If an error occurs, then the rest of the callbacks are not called.
  cb => http.get('endpoint-2.json', null, cb)
], (err, results) => {
  if (err) {
    console.log(err.body); // > { errors: [{ message: 'Error!' }] }
  } else {
    console.log(res.body); // > [{ result: { id: 1, ... } }, { result: { id: 2, ... } }]
  }
});

Running async functions in parallel:

import http from 'cf-util-http';
import {parallel} from 'cf-util-async';

parallel([
  cb => http.get('endpoint-1.json', null, cb),
  cb => http.get('endpoint-2.json', null, cb)
], (err, results) => {
  if (err) {
    console.log(err.body); // > { errors: [{ message: 'Error!' }] }
  } else {
    console.log(res.body); // > [{ result: { id: 1, ... } }, { result: { id: 2, ... } }]
  }
});
2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

7 years ago

2.2.2

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.0.0

8 years ago