Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.

Use ES6 Promise in place of callbacks #144

Open
mortenn opened this issue Oct 16, 2017 · 5 comments
Open

Use ES6 Promise in place of callbacks #144

mortenn opened this issue Oct 16, 2017 · 5 comments

Comments

@mortenn
Copy link
Contributor

mortenn commented Oct 16, 2017

I think this would be a beneficial change long term - 6.0?

@thedark1337
Copy link
Member

if people want to use Promise, node v8's promisfy or bluebird's promisfy function is a viable option. 90% of the callbacks plugAPI provides is in the correct form of callback(err, data) => {}; (There are a few that only callback(data) )

I see no benefit of having to rewrite the entire lib to use promises and making people change their existing code to have to use promises.

@Dazzuh
Copy link
Collaborator

Dazzuh commented Oct 16, 2017 via email

@mortenn
Copy link
Contributor Author

mortenn commented Oct 16, 2017

In my opinion, using a standard feature of the platform is a benefit in and of itself.

@mortenn
Copy link
Contributor Author

mortenn commented Oct 16, 2017

As a kind of compromise, maybe methods that take a callback could return a promise if called without a callback argument?

@mortenn
Copy link
Contributor Author

mortenn commented Oct 17, 2017

As an interim solution, I wrote this function:

function toPromise(call)
{
	return new Promise(
		function(resolve, reject)
		{
			call(
				function(err, data)
				{
					if(err)
						return reject(err);
					resolve(data);
				}
			);
		}
	);
}

Or, if you want to be slightly more evil:

function toPromise(call)
{
	return new Promise(
		(resolve, reject) => call((err, data) => err ? reject(err) : resolve(data))
	);
}

;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants