This will ask two players simultaneously. My example waits for each player to provide a valid name in turn.
back
1 comments
ok, sure, but it's still fixable without having to use await. you'd have to forego the for loop and make that flow control part of the callback cycle.
was your point that it couldn't be done with callbacks? or couldn't be done easily? or not easily alongside traditional flow control like for loops?
I agree, await and async in C# are very nice, I just took your post as a challenge.
get_player_name = (player, next) ->
ask "what's your name?", (response) ->
if is_valid_name response
player.name = response
next!
else get_player_name player, next
get_player_names = ([player,...players]) ->
get_player_name player, ->
if players.length > 0
get_player_names players
get_player_names playersExactly, this was my point.
It took me about as long as I typed this code to write it.
Of course it is doable with callbacks, but I know I'm not smart enough to do it in a comment field on HN.