Skip to content

Instantly share code, notes, and snippets.

@coolsoftwaretyler
Created September 12, 2019 21:07
Show Gist options
  • Save coolsoftwaretyler/3d7ebbf4cdb56f85486f3ef8ca463231 to your computer and use it in GitHub Desktop.
Save coolsoftwaretyler/3d7ebbf4cdb56f85486f3ef8ca463231 to your computer and use it in GitHub Desktop.

Revisions

  1. coolsoftwaretyler created this gist Sep 12, 2019.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    doSomeLongRunningTask(function(response, error) {
    // This function is running as a CALLBACK inside the long task
    // So it logs on completion
    console.log(response)

    // Return the response
    return response;
    }

    var res = doSomeLongRunningTask(function(response, error) {
    // You might expect response to get returned and assigned to `res`
    // But since the task runs long, and you haven't asked to await it, your `res` var gets `undefined`
    return response;
    }

    var res = await doSomeLongRunningTask(function(response, error) {
    // As long as `doSomeLongRunningTask` is an async function, you can `await` it, and `res` will get assigned at the end of the long task
    return response;
    }