Skip to content

Instantly share code, notes, and snippets.

@aheckmann
Created September 15, 2016 23:39
Show Gist options
  • Save aheckmann/20a7f55022d659038cb4f830ad5f9c71 to your computer and use it in GitHub Desktop.
Save aheckmann/20a7f55022d659038cb4f830ad5f9c71 to your computer and use it in GitHub Desktop.
'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
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment