Skip to content

Instantly share code, notes, and snippets.

@piscisaureus
Created May 2, 2014 17: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 piscisaureus/86ccc2eb34f1f195218b to your computer and use it in GitHub Desktop.
Save piscisaureus/86ccc2eb34f1f195218b to your computer and use it in GitHub Desktop.
var contents = yield fs.readFile('bla');
yield zone.create(() => {
http.get('google.com/bla').pipe(fs.createWriteStream('cache/file1'))
http.get('google.com/bl2').pipe(fs.createWriteStream('cache/file2'))
http.get('google.com/bl3').pipe(fs.createWriteStream('cache/file3'))
});
console.log('all done!')
@crandmck
Copy link

crandmck commented May 2, 2014

I added var fs = require('fs'); at the top, but when I run this I still get an error:

var contents = yield fs.readFile('bla');
                     ^^
SyntaxError: Unexpected identifier

@piscisaureus
Copy link
Author

Well, I think this came up earlier, but generators (yield) support is not implemented yet for zones.
The error you're seeing is caused by the fact that generator support for node needs to be turned on with a flag, try:

node --harmony zone-yield.js

That still won't do anything useful but it turns on generator support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment