Skip to content

utils.delay: use macro tasks instead of micro tasks. #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = function(grunt) {
'saucelabs-qunit': {
all: {
options: {
urls: ["http://127.0.0.1:9999/test/index.html"],
urls: ["http://127.0.0.1:9999/test/index.html?hidepassed"],
build: process.env.TRAVIS_JOB_ID,
throttled: 3,
"max-duration" : 600, // seconds, IE6 is slow
Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var support = require('./support');
var base64 = require('./base64');
var nodejsUtils = require('./nodejsUtils');
var asap = require('asap');
var setImmediate = require('core-js/library/fn/set-immediate');
var external = require("./external");


Expand Down Expand Up @@ -372,7 +372,7 @@ exports.pretty = function(str) {
* @param {Array} args the arguments to give to the callback.
*/
exports.delay = function(callback, args, self) {
asap(function () {
setImmediate(function () {
callback.apply(self || null, args || []);
});
};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
"tmp": "0.0.28"
},
"dependencies": {
"core-js": "~2.3.0",
"es6-promise": "~3.0.2",
"pako": "~1.0.0",
"readable-stream": "~2.0.6",
"asap": "~2.0.3"
"readable-stream": "~2.0.6"
},
"license": "(MIT OR GPL-3.0)"
}
40 changes: 22 additions & 18 deletions test/asserts/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ QUnit.module("stream", function () {

QUnit.module("internal");

test("A stream is pausable", function () {
// let's get a stream that generates a lot of chunks
test("A stream is pausable", function (assert) {
// let's get a stream that generates a lot of chunks (~40)
var zip = new JSZip();
var txt = "a text";
for(var i = 0; i < 10; i++) {
Expand All @@ -16,33 +16,37 @@ QUnit.module("stream", function () {

var allowChunks = true;
var chunkCount = 0;
var done = assert.async();

var helper = zip.generateInternalStream({streamFiles:true, type:"binarystring"});
helper
.on("data", function () {
chunkCount++;
equal(allowChunks, true, "be sure to get chunks only when allowed");
assert.equal(allowChunks, true, "be sure to get chunks only when allowed");

/*
* We stop at ~ half of chunks.
* A setTimeout aside this stream is not reliable and can be
* triggered *after* the completion of the stream.
*/
if (chunkCount === 20) {

allowChunks = false;
helper.pause();
setTimeout(function () {
allowChunks = true;
helper.resume();
}, 50);
}
})
.on("error", function (e) {
start();
ok(false, e.message);
done();
assert.ok(false, e.message);
})
.on("end", function () {
start();
done();
});
stop();
helper.resume();
setTimeout(function () {
allowChunks = false;
ok(chunkCount > 0, "the stream emitted at least 1 chunk before pausing it");
helper.pause();
}, 10);
setTimeout(function () {
allowChunks = true;
helper.resume();
}, 40);


});

QUnit.module("nodejs");
Expand Down
2 changes: 2 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
var details = log[i];
tests.push({
name: details.name,
message: details.message,
module: details.module,
result: details.result,
expected: details.expected,
actual: details.actual,
Expand Down