wrapr
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

wrapr

npm version

Middleware wrapper logic for asynchronous functions.

const wrapr = require('wrapr');
const fetch = require('node-fetch');

wrapr.retrying(wrapr.throttling(fetch))('https://example.com');

wrapr.retrying(wrapr.throttling(args => fetch(args.init, args.url)))({
  url: 'https://example.com',
  init: {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ foo: 1 }),
  },
});

wrapr.retrying(wrapr.throttling(async url => {
  try {
    return await fetch(url);
  } catch (err) {
    if (err.message.startsWith('HTTP')) {
      throw new wrapr.NonRetryableError(err.message);
    } else {
      throw err;
    }
  }
}))('https://example.com');

wrapr is distributed under the terms of the MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i wrapr

Weekly Downloads

37

Version

0.0.2

License

MIT

Unpacked Size

8.34 kB

Total Files

7

Last publish

Collaborators

  • kjscheibo