ibm-cloud-docs / openwhisk

Prod repo for IBM Cloud Functions docs
9 stars 36 forks source link

Async Await Examples? #184

Closed LouisIV closed 4 years ago

LouisIV commented 4 years ago

You only provide documentation for Promises. I have seen other IBM documentation that hints at async-await support.

For instance, can I do this?

function main(args) {
    return async () => {
      // await work
      return { payload: "Hello World" }
    }
}

Or can I even make main async directly?

async function main(args) {
    // await work
    return { payload: "Hello World" }
}
kersten1 commented 4 years ago

Hi @LouisIV Do you mean like this:

async function main() {
    ...some synchronous code...
    await doGet(callback => {
        ...log result...  // <-- this line gets now executed BEFORE the below synchronous code block is reached
    });
    ...some synchronous code...  // <-- the whole function now behaves as if it was only using synchronous code
}

This type of code will work in IBM Cloud functions.