Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Async bug? #42

Closed
pheze opened this Issue · 3 comments

3 participants

@pheze

This:

sleep = { setTimeout #1, #0 }

for x in [1,2,3]
  sleep!(100)
  console.log(x)

Results in:

var sleep;

sleep = function() {
   return setTimeout(arguments[1], arguments[0]);
};

for (x in [ 1, 2, 3 ]) sleep(100, function() {});  

console.log(x);

Shouldn't the console.log be included in the sleep callback?

@weepy
Owner

good catch ! not sure what's going on here

@amigrave

Kaffeine is doing things right here !

You're writing coffeescript like syntax so it is harder to point out what's wrong.
Kaffeine does not uses whitespace indentation.

For kaffeine those three code blocks are the same :

for x in [1,2,3]
    sleep!(100)
    console.log(x)
for x in [1,2,3]
    sleep!(100)
console.log(x)
for x in [1,2,3] {
    sleep!(100)
}
console.log(x)

See ? you only have the sleep statement in the loop, as such, kaffeine has no statement to give to the async, so it uses an empty function.

What you really want is this:

sleep = { setTimeout #1, #0 }

for x in [1,2,3] {
  sleep!(100)
  console.log(x)
}

results to

var sleep; sleep = function() { return setTimeout(arguments[1], arguments[0]) }

for(x in [1,2,3]) {
  sleep(100, function() {
  console.log(x) })
}
@weepy
Owner

yes of course ! -- Kaffeine is more like Javascript than CoffeeScript ^_^

closing for now.

@weepy weepy closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.