coffee-script icon indicating copy to clipboard operation
coffee-script copied to clipboard

Make `multi` accessible from outside Rendezvous

Open int3 opened this issue 12 years ago • 1 comments
trafficstars

Use case: I'm writing a CPS interpreter. ICS has proven invaluable for simplifying the code, but the call-defer-once limitation means that I can't write generators that yield more than once. I could rewrite things to use Rendezvous, but that seems unnecessarily ugly.

It seems that the deferral ID and multiple-invocation features that Rendezvous provides are orthogonal, so I think it would be nice if we could have something like deferMulti. The downside is that this introduces an extra keyword; a compile-time flag could be a viable alternative.

int3 avatar Feb 14 '13 07:02 int3

Interesting!

I don't have an opinion on this, more just curious about how the deferMulti would work in practice.

To understand what you're saying, if I wrote something like this (assuming my defer allows multiple calls):

bar = (cb) ->
  await foo defer()
  console.log 'x'
  cb()

And foo emitted two callbacks, then this would print 'x' twice and bar itself would callback twice?

A more complicated example. If I did this:

await
  foo defer()
  car defer()
console.log "both called back"

would the number of continuations outside the await be the minimum of the number of callbacks from both foo and car? i.e., if foo called back 3 times and car called back twice, would this print "both called back" 2 times?

And last question: what does this do, if c.doWhatever emits multiple callbacks?

  for c in connections
     await c.doWhatever defer()

I can't imagine wanting to do that last one, just curious the expected behavior.

Like I said, I have no opinion on this, just trying to get my head around it.

malgorithms avatar Feb 15 '13 02:02 malgorithms