Comparing version 0.2.0 to 0.2.1
@@ -0,0 +0,0 @@ var Y = require('..'); |
@@ -0,0 +0,0 @@ var fs = require('fs'); |
@@ -5,3 +5,3 @@ var Y = require('..'); | ||
Y(function* () { | ||
var pages = ['http://google.com', 'http://yahoo.com', 'http://bind.com']; | ||
var pages = ['http://google.com', 'http://yahoo.com', 'http://bing.com']; | ||
var content = yield pages.map(function(url) { | ||
@@ -8,0 +8,0 @@ return get(url); |
@@ -0,0 +0,0 @@ var fs = require('fs'); |
@@ -0,0 +0,0 @@ var Y = require('..'); |
@@ -0,0 +0,0 @@ var Y = require('..'); |
@@ -0,0 +0,0 @@ var Y = require('..'); |
@@ -0,0 +0,0 @@ var q = require('q'); |
@@ -0,0 +0,0 @@ var fs = require('fs'); |
@@ -0,0 +0,0 @@ var Y = require('..'); |
@@ -24,3 +24,3 @@ (function (factory) { | ||
Y.VERSION = '0.2.0'; | ||
Y.VERSION = '0.2.1'; | ||
@@ -27,0 +27,0 @@ |
{ | ||
"name": "yielding", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Easy generators", | ||
@@ -5,0 +5,0 @@ "main": "./lib/yielding.js", |
@@ -38,3 +38,3 @@ yielding | ||
Y(function* () { | ||
var pages = ['http://google.com', 'http://yahoo.com', 'http://bind.com']; | ||
var pages = ['http://google.com', 'http://yahoo.com', 'http://bing.com']; | ||
var content = yield pages.map(function(url) { | ||
@@ -41,0 +41,0 @@ return get(url); |
@@ -83,2 +83,35 @@ var Y = require('..'); | ||
}); | ||
it('toArray() Async', function(done) { | ||
var getContent = Y.nwrap(fs.readFile); | ||
var getAll = Y(function* (files) { | ||
for (var i = 0; i < files.length; i++) { | ||
yield getContent(files[i], 'utf8'); | ||
} | ||
}); | ||
Y(function* () { | ||
var files = ['examples/Y.js', 'examples/Y-async.js', 'examples/ncall.js']; | ||
var content = yield getAll.toArray(files); | ||
content.forEach(function(c) { | ||
expect(c).to.be.a('string'); | ||
expect(c.length > 0).to.be.true; | ||
}); | ||
done(); | ||
})(); | ||
}); | ||
it('parallel execution', function(done) { | ||
var read = Y.nwrap( fs.readFile ); | ||
Y(function* () { | ||
var files = ['examples/Y.js', 'examples/Y-async.js']; | ||
var content = yield files.map(function(file) { | ||
return read(file, 'utf8'); | ||
}); | ||
content.forEach(function(c) { | ||
expect(c).to.be.a('string'); | ||
expect(c.length > 0).to.be.true; | ||
}) | ||
done(); | ||
})(); | ||
}); | ||
}); | ||
@@ -90,3 +123,3 @@ | ||
var read = Y.nwrap(fs.readFile); | ||
var readWithParams = Y.nwrap(fs.readFile, filename, 'utf-8'); | ||
var readWithParams = Y.nwrap(fs.readFile, filename, 'utf8'); | ||
@@ -117,3 +150,3 @@ it('return promise', function () { | ||
Y(function *async() { | ||
var content = yield fs.readFile('test/example.txt', 'utf-8', async.resume); | ||
var content = yield fs.readFile('test/example.txt', 'utf8', async.resume); | ||
expect(content).to.be.equal('Hello'); | ||
@@ -138,3 +171,3 @@ done(); | ||
try { | ||
expect(yield fs.readFile('non_exists_file', 'utf-8', async.resume)).to.be.undefined; | ||
expect(yield fs.readFile('non_exists_file', 'utf8', async.resume)).to.be.undefined; | ||
} catch (e) { | ||
@@ -147,2 +180,8 @@ expect(e).to.be.instanceof(Error); | ||
}); | ||
it('resume in anonymous function', function() { | ||
Y(function* () { | ||
expect(arguments.callee.resume).to.be.a('function'); | ||
})(); | ||
}); | ||
}); | ||
@@ -155,3 +194,3 @@ | ||
try { | ||
expect(yield Q.nfcall(fs.readFile, 'non_exists_file', 'utf-8')).to.be.undefined; | ||
expect(yield Q.nfcall(fs.readFile, 'non_exists_file', 'utf8')).to.be.undefined; | ||
} catch (e) { | ||
@@ -158,0 +197,0 @@ expect(e).to.be.instanceof(Error); |
15792
390