Skip to content

Instantly share code, notes, and snippets.

@sebinsua
Created April 27, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebinsua/fa1a8029765098efb3b3 to your computer and use it in GitHub Desktop.
Save sebinsua/fa1a8029765098efb3b3 to your computer and use it in GitHub Desktop.
Testing Babel async styles in Node v0.10.29
import Promise from 'bluebird';
async function bar(message) {
const newMessage = await new Promise(function (resolve, reject) {
console.log(message);
resolve(`${message} printed`);
});
return newMessage;
}
export default async (message) => {
var newMessage = await bar(message);
console.log(newMessage);
};
import Promise from 'bluebird';
import co from 'co';
function *foo() {
console.log("inside");
var data = yield Promise.resolve("fake-data");
return data;
};
export default function () {
return co(function *() {
var data = yield foo;
console.log(data);
});
};
{
"name": "test-async-babel",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel": "^5.1.13",
"bluebird": "^2.9.24",
"co": "^4.5.2"
}
}
require('babel/register')({
optional: ['es7.asyncFunctions']
});
var asyncTest = require('./async');
asyncTest("Hey");
require('babel/register');
var coTest = require('./co');
coTest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment