Created
April 27, 2015 14:05
-
-
Save sebinsua/fa1a8029765098efb3b3 to your computer and use it in GitHub Desktop.
Testing Babel async styles in Node v0.10.29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('babel/register')({ | |
optional: ['es7.asyncFunctions'] | |
}); | |
var asyncTest = require('./async'); | |
asyncTest("Hey"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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