Skip to content

aercolino/promise-to-call

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Promise to Call Build Status Coverage Status

Replace callbacks with promises.

Targets to call can be methods of objects (useful "this") or functions (useless "this").

Installation

$ npm install promise-to-call

Usage

const promiseTo = require('promise-to-call');

promiseTo.$callMethod(someObject, 'someMethod', 2, 3)
    .then((data) => { ... })
    .catch((err) => { ... });

promiseTo.$callFunction(someFunction, 2, 3)
    .then((data) => { ... })
    .catch((err) => { ... });

Example

const AWS = require('aws-sdk');
const promiseTo = require('promise-to-call');

function whoAmI() {
    const stsService = new AWS.STS({ region: 'us-east-1' });
    return promiseTo.$callMethod(stsService, 'getCallerIdentity', {})
        .then((data) => {
            return data.Account;
        })
        .catch(console.error);
}

whoAmI().then(console.log); // -> 123456789012

Options

This module uses Promise by default. If you want to use some other class, do this:

promiseTo.usePromiseClass(SomePromiseClass);

promiseTo.usePromiseClass(); // back to using Promise

Tests

$ npm test

About

Replace callbacks with promises.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published