Skip to content
/ wrapr Public

Middleware wrapper logic for asynchronous functions

License

Notifications You must be signed in to change notification settings

scheibo/wrapr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Middleware wrapper logic for asynchronous functions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published