Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coffee-script support for promises? #3036

Closed
iamwilhelm opened this issue Jun 14, 2013 · 2 comments
Closed

Coffee-script support for promises? #3036

iamwilhelm opened this issue Jun 14, 2013 · 2 comments

Comments

@iamwilhelm
Copy link
Contributor

(I would search issues first if I could), but I was wondering if coffeescript had ever entertained a syntax to make it less messy to write promises?

when using promises, it usually looks pretty messy, because you have to wrap it inside of the promises functions, and you have to 'lift' the functions.

wn = require('when')
wnf = require('when/node/function')

wn(
  wnf.lift(method)(arg)
).then(
  wnf.lift(method2)(arg1, arg2)
).then((result) ->
  callback(result)
).otherwise((err) ->
  callback(err)
)

I was wondering if coffeescript would entertain having syntax that makes it easier.

wn(
  ^method(arg) ;;
  ^method2(arg1, arg2) ;result;
  callback(result) |err|
    callback(err)
)

I just made that up on the spot, just to illustrate a possible syntax. I'm not sure there needs to be a difference between ;; and || for then() and otherwise()

@vendethiel
Copy link
Collaborator

(I would search issues first if I could),

You can ! Here :

when using promises, it usually looks pretty messy, because you have to wrap it inside of the promises functions, and you have to 'lift' the functions.

Why so ? You're only using a poor style to write them, imho. This works and is quite clear :

wn = require('when')
wnf = require('when/node/function')

wn ->
  method arg
.then ->
  method arg
.then ->
  method arg, arg2
.then (result) ->
  callback result
.otherwise (err) ->
  callback err

I was wondering if coffeescript would entertain having syntax that makes it easier.

I don't see a special syntax for promises being added. The syntax you proposed is clearly far too cryptic and would be a no-go for me (if proposed seriously).
However, we have #2762 for backcalls (which actually doesn't really help here).

@michaelficarra
Copy link
Collaborator

This is a duplicate of #1495. That thread is huge now.

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

No branches or pull requests

3 participants