maxtaco / coffee-script

IcedCoffeeScript
http://maxtaco.github.com/coffee-script
MIT License
726 stars 58 forks source link

await / defer in a function? #170

Closed jayjanssen closed 8 years ago

jayjanssen commented 8 years ago

I know I'm missing something really dumb here:

request = require 'request'

test_function = () ->
    console.log "Step 2"
    await request 'http://www.google.com', defer(error, response, data)
    console.log "Step 3"

console.log "Step 1"

test_function()

console.log "Step 4"

My output is:

1
2
4
3

I'm obviously (I think) expecting numerical order. What am I doing wrong?

maxtaco commented 8 years ago

test_function itself needs to take a cb and you need to await / defer on it.