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

Use ES6 Promise in place of callbacks #144

Open

Description

@mortenn

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

Activity

  1. thedark1337 commented on Oct 16, 2017

    @thedark1337
    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.

  2. Dazzuh commented on Oct 16, 2017

    @Dazzuh
    Collaborator
  3. mortenn commented on Oct 16, 2017

    @mortenn
    ContributorAuthor

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

  4. mortenn commented on Oct 16, 2017

    @mortenn
    ContributorAuthor

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

  5. mortenn commented on Oct 17, 2017

    @mortenn
    ContributorAuthor

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions