Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

suspend

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

suspend - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

test/run.js

98

api-playground.js
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc