How do Fibers and Meteor.asyncWrap work?

We should actually just use async/await in Meteor 1.3+ now. On the server, async functions are implemented with Fibers. So, I’d actually just do this now instead of dealing with Fibers directly:

function asyncRequest(url) {
    return new Promise((resolve, reject) => {
        request(url, (error, response, body) => {
            if (error) reject(error)
            resolve({response, body})
        })
    })
}

async function main() {
    let result = await asyncRequest("http://google.com")
    console.log(result.response, result.body)
}

main()

See this thread on how to promisify non-promise-based Meteor APIs.

There’s also talk of making promise-versions of Meteor APIs too, which will make it easy to use Meteor APIs with async/await out of the box, without having to do the promisifying steps yourself (no need to make a function that wraps the API with a Promise and returns that Promise). For example, just

const doc = await Docs.findOneAsync(docId)