Skip to content

Suggest using promises instead of callbacks #1

@MarquisdeGeek

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

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