treaty

1.0.0 • Public • Published

Treaty

You can think of a treaty as a Promise with one key difference: you can resolve or reject a treaty with multiple arguments.

const treaty = require('treaty');
 
let test = treaty((resolve, reject) => {
 
    let message = 'this was fun';
 
    doSomethingAsync((error, data) => {
        
        if (error) {
            reject(error, message);
        } else {
            resolve(data, message);
        }
    });
});
 
// Arguments get passed here:
test.then((data, message) => {
    console.log(message);
    doSomethingWith(data);
});
 
test.catch((error, message) => {
    console.error(message);
    doSomethingElseWith(error);
});

And of course, you can chain it all together if that's your style:

require('treaty')((resolve, reject) => {
 
    let message = 'this was fun';
 
    doSomethingAsync((error, data) => {
        
        if (error) {
            reject(error);
        } else {
            resolve(data, message);
        }
    });
}).then((data, message) => {
    console.log(message);
    doSomethingWith(data);
}).catch((error, message) => {
    console.error(message);
    doSomethingElseWith(error);
});

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    0
  • 0.0.3
    0
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i treaty

Weekly Downloads

0

Version

1.0.0

License

ISC

Last publish

Collaborators

  • mgrahamjo