Created
September 12, 2019 21:07
-
-
Save coolsoftwaretyler/3d7ebbf4cdb56f85486f3ef8ca463231 to your computer and use it in GitHub Desktop.
Revisions
-
coolsoftwaretyler created this gist
Sep 12, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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; }