4 ms·
There is a way around it. Here, everything after the await is transformed into a callback for the await magic: waity = (forFn) -> await forFn defer r
by timruffles 15y ago
There is a way around it. Here, everything after the await is transformed into a callback for the await magic:
waity = (forFn) ->
await forFn defer r1, r2
console.log "values of defer variables", r1, r2
return "this only returns from the result callback, not waity"
syncReturn = waity (cb) ->
setTimeout ->
cb "r1 val", "r2 val"
console.log "waity's synchronous return value:", syncReturn
So our output is:
waity's synchronous return value: undefined
values of defer variables r1 val r2 val
To return, you can simply write:
waity = (forFn) ->
setTimeout ->
await ...
return "works as normal"