weepy / kaffeine

Extended Javascript for Pros
http://weepy.github.com/kaffeine/
MIT License
180 stars 16 forks source link

Async bug? #42

Closed pheze closed 11 years ago

pheze commented 12 years ago

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 commented 12 years ago

good catch ! not sure what's going on here

amigrave commented 11 years ago

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 commented 11 years ago

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

closing for now.