Skip to content

Instantly share code, notes, and snippets.

@aseemk
Created July 16, 2011 01:12
Show Gist options
  • Save aseemk/1085874 to your computer and use it in GitHub Desktop.
Save aseemk/1085874 to your computer and use it in GitHub Desktop.
Streamline bug due to switch case w/out a break (CoffeeScript optimization)
async = (_) ->
setTimeout _, 1000
switch true
when true
alert 'about to start async'
async _
# this never executes!
alert 'done w/ async'
function async(_) {
setTimeout(_, 1000);
}
switch (true) {
case true:
alert('about to start async');
async(_);
}
// this never executes!
alert('done w/ async');
function async(_) {
setTimeout(_, 1000);
}
switch (true) {
case true:
alert('about to start async');
async(_);
// but when we add this explicit break:
break;
}
// this does execute now:
alert('done w/ async');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment