Merge remote-tracking branch 'origin/rewrite' into rewrite

This commit is contained in:
Leo Horie 2016-08-03 22:37:29 -04:00
commit d6e18ca134
3 changed files with 67 additions and 12 deletions

View file

@ -1,3 +1,57 @@
"use strict"
module.exports = typeof setImmediate === "function" ? setImmediate : setTimeout
/**
* This is modeled after Bluebird's scheduler. It solves for quite a few edge
* cases, and should help alleviate most of the flakiness issues. It also speeds
* up the suite a bit.
*/
module.exports = (function () {
// The scheduler for NodeJS/io.js is setImmediate for recent versions of
// node because of macrotask semantics (i.e. don't starve the event loop).
if (typeof process !== "undefined" &&
/^\[object process\]/i.test({}.toString.call(process))) {
var version = process.versions.node.split(".").map(Number)
var isRecent = version[0] === 0 && version[1] > 10 || version[0] > 0
return isRecent ? setImmediate : process.nextTick
}
if (typeof Promise === "function") {
var p = Promise.resolve()
return function (fn) {
p.then(fn)
}
}
if (typeof MutationObserver !== "undefined") {
// Using 2 mutation observers to batch multiple updates into one.
var div = document.createElement("div")
var opts = {attributes: true}
var toggleScheduled = false
var div2 = document.createElement("div")
var o2 = new MutationObserver(function() {
div.classList.toggle("foo")
toggleScheduled = false
})
o2.observe(div2, opts)
function scheduleToggle() {
if (toggleScheduled) return
toggleScheduled = true
div2.classList.toggle("foo")
}
return function (fn) {
var o = new MutationObserver(function() {
o.disconnect()
fn()
})
o.observe(div, opts)
scheduleToggle()
}
}
return typeof setImmediate === "function" ? setImmediate : setTimeout
})()

View file

@ -20,6 +20,6 @@ o.spec("callAsync", function() {
})
timeout = setTimeout(function() {
throw new Error("callAsync was called too slow")
}, 0)
}, 5)
})
})
})

View file

@ -173,7 +173,7 @@ o.spec("stream", function() {
Stream.stream("20"),
Stream.stream({value: 30}),
])
o(all()).deepEquals([10, "20", {value: 30}])
})
o("remains pending until all streams are active", function() {
@ -184,7 +184,7 @@ o.spec("stream", function() {
Stream.stream("20"),
straggler,
])
o(all()).equals(undefined)
straggler(30)
@ -549,15 +549,16 @@ o.spec("stream", function() {
var absorbed = Stream.stream()
var mapped = stream.run(function(value) {return absorbed})
var depCallCount = 0
mapped.map(function (value) {
o(value).equals(200)
depCallCount += 1
})
o(depCallCount).equals(0)
// TODO: uncomment when fixed.
// var depCallCount = 0
// mapped.map(function (value) {
// o(value).equals(200)
// depCallCount += 1
// })
// o(depCallCount).equals(0)
absorbed(200)
o(depCallCount).equals(1)
// o(depCallCount).equals(1)
o(mapped()).equals(200)
})*/