1.1.4 • Published 9 years ago

silently v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
9 years ago

silently

Circle CI

silently is a function that is used to invoke another function that you want to fail silently (meaning that any errors that it throws must be suppressed). The main motivation behind it was to allow me to be able to do the following...

Promise.all([
    doSomething(),
    silently(doSomeOtherThing)
])
.then(results => {
    console.log(results[0]);
    console.log(results[1]);
});

Promise.all will normally reject if one of the promises rejects and I found myself in situations when I didn't want it to reject because one promise rejected. In the above example, if doSomeOtherThing() returns a promise that rejects, or if it throws an error, the error would be handled silently and undefined would be logged to the console for result[1].

Installation

$ npm install silently --save

Usage

function doSomething() {
    throw new Error('something went wrong');
}

var result = silently(doSomething); // result is undefined

Or with promises...

function doSomethingAsynchronously() {
    return new Promise((resolve, reject) => {
        reject(new Error('something went wrong'));
    })
}

silently(doSomethingAsynchronously)
    .then(result => {
        console.log(result); // undefined will be logged to the console
    })

If you want to pass args to the function, you can do the following

function doSomething(arg1, arg2) {
    return arg1 + ' ' + arg2;
}

var result = silently
                .call(doSomething)
                .boundTo(null, 'hello', 'world')
                .asap(); // result will be 'hello world'

This is just a more fluent way of doing silently(doSomething.bind(null, 'hello', 'world');

Sugar

The following sugar is also supported, which is also the same as doing silently.call()...

silently.called(action)...
silenlty.do(action)...

Running the tests

make install
make dev
make test
1.1.4

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago