f = (callback) ->
callback null, 2
test = (a, callback) ->
console.log a
while true
console.log a
await f defer(error, a)
console.log a
break
test 1, (error, a) ->
console.log a
This prints:
1
undefined
2
While it should print:
1
1
2
Using the a variable in any way after the while in the test function fixes the problem.
This prints:
While it should print:
Using the
a
variable in any way after thewhile
in thetest
function fixes the problem.