Skip to content

Suggest using promises instead of callbacks #1

Description

@MarquisdeGeek

I find callbacks become unwieldy when more than a couple are nested, so I'd be tempted to wrap methods in promises. e.g.

     function whoAmIWithPromises() {
        var d = $.Deferred();

        Ipseorama.whoAmI(function(myfingerprint) {
            d.resolve(myfingerprint);
        }, function(err) {
            d.reject(err);
        });

        return d.promise();
    }

With the equivalent calling code reading:

whoAmIWithPromises().done(function(myfingerprint) {
   gotFinger(myfingerprint);
}).fail(function(errorCase) {
   console.log("could not create identity " + errorCase);
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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