Comparing version 0.3.0 to 0.3.1
var suspend = require('./'), | ||
Q = require('q'), | ||
fs = require('fs'); | ||
Q = require('q'), | ||
fs = require('fs'), | ||
_ = require('underscore'), | ||
request = require('request'); | ||
// suspend(function* (resume) { | ||
// // read the current file | ||
// var res = yield fs.readFile(__filename, { encoding: 'utf8' }, resume); | ||
// // replace tabs with spaces | ||
// var newContents = res[1].replace(/\t/g, ' '); | ||
// // write back changes | ||
// //yield fs.writeFile(__filename, newContents, resume); | ||
// // print modified file | ||
// var modified = yield fs.readFile(__filename, { encoding: 'utf8'}, resume); | ||
// console.log(modified[1]); | ||
// // read the current file | ||
// var res = yield fs.readFile(__filename, { encoding: 'utf8' }, resume); | ||
// // replace tabs with spaces | ||
// var newContents = res[1].replace(/\t/g, ' '); | ||
// // write back changes | ||
// //yield fs.writeFile(__filename, newContents, resume); | ||
// // print modified file | ||
// var modified = yield fs.readFile(__filename, { encoding: 'utf8'}, resume); | ||
// console.log(modified[1]); | ||
// })(); | ||
@@ -19,9 +21,9 @@ | ||
// suspend(function* (resume) { | ||
// console.log('starting cb version'); | ||
// yield sleepCb(1000, resume); | ||
// console.log('done'); | ||
// console.log('starting cb version'); | ||
// yield sleepCb(1000, resume); | ||
// console.log('done'); | ||
// console.log('starting promise version'); | ||
// yield sleepPromises(1000); | ||
// console.log('done'); | ||
// console.log('starting promise version'); | ||
// yield sleepPromises(1000); | ||
// console.log('done'); | ||
// })(); | ||
@@ -31,16 +33,60 @@ | ||
// function sleepCb(duration, cb) { | ||
// setTimeout(cb, duration); | ||
// setTimeout(cb, duration); | ||
// } | ||
// function sleepPromises(duration) { | ||
// var deferred = Q.defer(); | ||
// setTimeout(deferred.resolve, duration); | ||
// return deferred.promise; | ||
// var deferred = Q.defer(); | ||
// setTimeout(deferred.resolve, duration); | ||
// return deferred.promise; | ||
// } | ||
suspend(function* (resume) { | ||
console.log('hello'); | ||
yield setTimeout(resume, 1000); | ||
console.log('world'); | ||
})(); | ||
// suspend(function* (resume) { | ||
// yield setTimeout(resume, 1000); | ||
// console.log('foo'); | ||
// yield setTimeout(resume, 1000); | ||
// console.log('bar'); | ||
// })(); | ||
// suspend(function* (resume) { | ||
// while (true) { | ||
// try { | ||
// console.log('success', yield request('http://www.unexistant.com', resume)); | ||
// } catch (err) { | ||
// console.log('error', err); | ||
// } | ||
// } | ||
// })(); | ||
// function* map(array, callback) { | ||
// for (var i = 0, len = array.length; i < len; i++) { | ||
// yield* callback(array[i]); | ||
// } | ||
// } | ||
var _ = require("underscore"); | ||
function myAsyncFunction(cb) { | ||
setTimeout(function() { | ||
cb(null, 'TEST'); | ||
}, 500); | ||
} | ||
// suspend(function* (resume) { | ||
// var myArray = [1,2,3,4,5]; | ||
// _.each(myArray, suspend(function*(element, index, list, resume) { | ||
// //A yield in here won't work, because this is a "regular" function passed as a parameter to _.each | ||
// var result = yield myAsyncFunction(resume); | ||
// console.log(result); | ||
// })); | ||
// })(); | ||
var myArray = [1,2,3,4,5]; | ||
_.each(myArray, suspend(function*(element, index, list, resume) { | ||
//A yield in here won't work, because this is a "regular" function passed as a parameter to _.each | ||
var result = yield myAsyncFunction(resume); | ||
console.log(result); | ||
})); | ||
@@ -6,3 +6,3 @@ { | ||
"keywords": ["async", "generator", "yield", "callback", "promise", "flow", "control", "suspend"], | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"repository": { | ||
@@ -14,7 +14,9 @@ "type" : "git", | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha --harmony-generators --reporter list" | ||
"test": "node test/run.js" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.11.x", | ||
"q": "0.9.x" | ||
"q": "0.9.x", | ||
"regenerator": "0.2.x", | ||
"semver": "2.2.x" | ||
}, | ||
@@ -21,0 +23,0 @@ "engines": { |
@@ -99,3 +99,3 @@ # suspend | ||
var printFile = suspend(function* (fileName, resume) { | ||
console.log(yield fs.readFile(filename, 'utf8', resume)); | ||
console.log(yield fs.readFile(fileName, 'utf8', resume)); | ||
}); | ||
@@ -102,0 +102,0 @@ |
Sorry, the diff of this file is not supported yet
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
22824
9
452
4
2
1