algorithmia-nodejs icon indicating copy to clipboard operation
algorithmia-nodejs copied to clipboard

Use a promise library

Open monteslu opened this issue 8 years ago • 2 comments

Results with a .then are generally thought to be promises. The issue here is that the result isn't a real promise and doesn't conform the promises A+ spec.

This becomes a problem for example if you want to handle an exception you might assume that you can attach a .catch() to the result.

monteslu avatar Feb 01 '17 22:02 monteslu

When this was written, we tried to conform to the promises/A+ spec available here: https://promisesaplus.com/

There is nothing about .catch() in that spec, just onFullfilled and onRejected callback arguments to .then().

I do see that mozilla defines .catch() in their native Promise type. Will look into what it would take to implement this. Pull requests are also gratefully accepted :-)

platypii avatar Feb 01 '17 22:02 platypii

I think it's the browser JS client that conforms a bit better to promises/A+.

I also don't see anything regarding .catch() in the spec, but I can at least enumerate a few places where this client is out-of-spec:

  • there is no onRejected - instead we always fulfill with a value that could contain a result or an error. This presumably makes it harder to compose effectively with other promise-wrapping libraries (async comes to mind)
  • we don't allow multiple callbacks, let alone a chainable interface or order guarantees

anowell avatar Feb 01 '17 22:02 anowell