Skip to content

Comment on Analyzing mbostock's queue.jsparent

Comments

Something else I'm unsure about: line 67, `results[i] = r`, refers from a closure back to i initialized at line 52 in a loop. If this loop pops more than one deferral, then won't each deferral's callback use the same i? Since Javascript assigns to function-level i in the loop, it doesn't bind a new one.

OTOH if the loop only ever pops at most one deferral, then an if instead of a while would make this clear.

Good catch! It appears I just introduced the bug here, by eliminating recursion: https://github.com/mbostock/queue/commit/7bd5059bb2c0a94c0ca...

Popping multiple synchronous tasks after an asynchronous one is fairly rare, but I’ll make sure the tests verify this code path.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.