Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created September 15, 2016 23:39
Show Gist options
  • Select an option

  • Save aheckmann/20a7f55022d659038cb4f830ad5f9c71 to your computer and use it in GitHub Desktop.

Select an option

Save aheckmann/20a7f55022d659038cb4f830ad5f9c71 to your computer and use it in GitHub Desktop.

Revisions

  1. aheckmann revised this gist Sep 15, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion await_thenables.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,6 @@
    // https://github.com/targos/node/commits/v8-5.4 (https://github.com/nodejs/node/pull/8317)
    //
    // node --harmony_async_await await_thenables.js
    //

    function counter(count) {
    return {
  2. aheckmann created this gist Sep 15, 2016.
    23 changes: 23 additions & 0 deletions await_thenables.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    'use strict';

    // run using this fork of NodeJS
    // https://github.com/targos/node/commits/v8-5.4 (https://github.com/nodejs/node/pull/8317)
    //
    // node --harmony_async_await await_thenables.js
    //

    function counter(count) {
    return {
    then: function(res, rej) {
    const p = Promise.resolve(count++);
    return p.then(res, rej);
    }
    }
    }

    ;(async function start() {
    let incr = counter(1335);
    console.log(await incr); // 1335
    console.log(await incr); // 1336
    console.log(await incr); // 1337
    })()