Skip to content

Support standard node callback pattern #7

@dhritzkiv

Description

@dhritzkiv

Currently, it seems that the callback only ever has one argument, with that sole argument representing either a result, or an object with a potential error in it:

api.goals.list(params, (result) => {
    if (result.error) {
          throw result.error;
    }

    //else result is the data we're looking for 
});

Ideally, the pattern would use the standard node callback pattern of (error, result):

api.goals.list(params, (err, result) => {
    if (err) {
          throw err;
    }

    //else result is the data we're looking for 
});

An advantage to this (other than predictable behaviour for new developers integrating this module) is easy compatibility with node v.8.x.'s promisify method to make methods into Promises*:

const asyncGetGoalsList = promisify(api.goals.list.bind(api));

versus the current:

const asyncGetGoalsList = (params) => new Promise((resolve, reject) => {
    api.goals.list(params, result => {
        if (result.error) {
            if (result.body) {
                  result.error.body = result.body;
            }

            return reject(result.error);
        }

        return resolve(result);
    });
});

*That being said, it'd also be nice if this library supported Promises in addition to callbacks.

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