News for hackers. Stuff that matters.
Re:Callbacks as our Generation's Goto Statement by singlow on Thursday August 15, 2013 @07:32PM (#6221274)
Maybe like this?

  players.forEach(function() {
    'use strict';
    var player = this;
    var name = Ask("What's your name?, function(name) {
      if (isValidName(name) {
        player.name = name;
      }
    });
  });
Re:Callbacks as our Generation's Goto Statement by danabramov on Thursday August 15, 2013 @07:34PM (#6221283)
Same problem like with the sibling post: this will ask two players simultaneously. My example waits for each player to provide a valid name in turn.
Re:Callbacks as our Generation's Goto Statement by captaincrowbar on Thursday August 15, 2013 @07:58PM (#6221379)
If you're doing everything sequentially anyway, why bother with the awaiting part? As far as I can see your example would be functionally unchanged if you wrote the same code except without the await keyword.
Re:Callbacks as our Generation's Goto Statement by scott_s on Thursday August 15, 2013 @10:59PM (#6221964)
Because it doesn't block the thread. The idea is that this code is executed inside of a thread that, if it blocks, will cause the application to hang. For example, in a GUI or a server. So, if its a thread driving a GUI, and it's blocked on user input, then the entire application interface will be unresponsive until it receives that input.
Re:Callbacks as our Generation's Goto Statement by danabramov on Friday August 16, 2013 @05:00AM (#6222907)
This. Specifically, I'm thinking about iOS prompts and alerts, they are not blocking.
Re:Callbacks as our Generation's Goto Statement by gruseom on Friday August 16, 2013 @03:41PM (#6226303)
Great comment! I missed that.
Re:Callbacks as our Generation's Goto Statement by singlow on Friday August 16, 2013 @12:30AM (#6222173)
Well, if the Ask function should only run once at a time, it should block itself.
Re:Callbacks as our Generation's Goto Statement by danabramov on Friday August 16, 2013 @05:00AM (#6222905)
Imagine it's an iOS modal prompt. It doesn't block the thread, it sends an event.