Comparing version 1.0.7 to 1.0.9
{ | ||
"name": "genify", | ||
"version": "1.0.7", | ||
"version": "1.0.9", | ||
"description": "Convert passed javascript object to generator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ genify | ||
Wrapping object generator properties into co | ||
Bringing power of javascript generators into normal javascript environment | ||
@@ -19,17 +19,26 @@ ### Installation | ||
var fs = require('fs'); | ||
var co = require('co'); | ||
var genify = require('genify'); | ||
// genify is taking care of wrapping all object generator properties into co function, | ||
// and returning generator result as resolved promise, | ||
// or in case of error -> rejected promise with error object | ||
// wrap your object into genify function | ||
var object = genify({ | ||
readFile: function * (file) { | ||
return yield Q.nfcall(fs.readFile, file); | ||
concatFiles: function * (file1, file2, outFile) { | ||
file1 = yield Q.nfcall(fs.readFile, file1); | ||
file2 = yield Q.nfcall(fs.readFile, file2); | ||
var concated = file1 + file2; | ||
yield Q.nfcall(fs.writeFile, outFile, concated); | ||
return concated; | ||
} | ||
}); | ||
co(function * () { | ||
console.log(yield object.readFile('./somefile.txt')); | ||
})(); | ||
// concatFiles is generator function, and it is using generator power to do some things, | ||
// and here you are using that power inside normal javascript environment, | ||
// handling results and errors using promises | ||
object.concatFiles('./somefile1.txt', './somefile2.txt', './concated.txt').then(function (res) { | ||
// do something with result | ||
}, function (err) { | ||
// do something with error | ||
}); | ||
``` | ||
@@ -36,0 +45,0 @@ |
@@ -92,3 +92,21 @@ 'use strict'; | ||
}); | ||
it('should contain .then on returned result', function () { | ||
var promise = object.readFile('./test/test.txt'); | ||
promise.should.have.property('then'); | ||
}); | ||
it('should be able to read value from promise', function (done) { | ||
var promise = object.readFile('./test/test.txt'); | ||
promise.then(function (res) { | ||
if (done) { | ||
done(); | ||
} else { | ||
done('No value returned!'); | ||
} | ||
}, done).done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5889
134
46