1.0.0 • Published 7 years ago

treaty v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
7 years ago

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);
});
1.0.0

7 years ago

0.0.3

7 years ago

0.0.2

9 years ago

0.0.1

9 years ago