Giter VIP home page Giter VIP logo

Comments (5)

thedark1337 avatar thedark1337 commented on August 12, 2024

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.

from plugapi.

Dazzuh avatar Dazzuh commented on August 12, 2024

from plugapi.

mortenn avatar mortenn commented on August 12, 2024

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

from plugapi.

mortenn avatar mortenn commented on August 12, 2024

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

from plugapi.

mortenn avatar mortenn commented on August 12, 2024

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

;)

from plugapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.