* Extract glob helpers that are needed in a CJS environment * Ensure ava/plugin works in a CJS environment Refactor and deploy some tricks so that ava/plugin is usable in a CJS environment, even if the rest of AVA's internals become ESM. * Ensure 'ava' can be imported in a CJS environment * Convert to ESM * Load yargs as CJS due to strange compatibility issues * Keep line number parsing code as CJS because it attempts to lazy-load dependencies * Shared workers are always loaded through a dynamic import * Shared worker filenames must now be file:// URLs, but you can provide a URL instance * Test file paths within shared workers are now file:// URLs * Error serialization and code excerpts now support ESM * Title prefixes in the reporters now correctly skip all test file extensions, not just `js` * CI: Increase delay on timeout test, mostly for Windows
40 lines
865 B
JavaScript
40 lines
865 B
JavaScript
'use strict';
|
|
function controlFlow(channel) {
|
|
let errored = false;
|
|
let deliverImmediately = true;
|
|
|
|
const backlog = [];
|
|
const deliverNext = error => {
|
|
if (error !== null) {
|
|
errored = true;
|
|
}
|
|
|
|
if (errored || !channel.connected) {
|
|
backlog.length = 0; // Free memory.
|
|
return; // We can't send.
|
|
}
|
|
|
|
let ok = true;
|
|
while (ok && backlog.length > 0) { // Stop sending after backpressure.
|
|
ok = channel.send(backlog.shift(), deliverNext);
|
|
}
|
|
|
|
// Re-enable immediate delivery if there is no backpressure and the backlog
|
|
// has been cleared.
|
|
deliverImmediately = ok && backlog.length === 0;
|
|
};
|
|
|
|
return message => {
|
|
if (errored || !channel.connected) {
|
|
return;
|
|
}
|
|
|
|
if (deliverImmediately) {
|
|
deliverImmediately = channel.send(message, deliverNext);
|
|
} else {
|
|
backlog.push(message);
|
|
}
|
|
};
|
|
}
|
|
|
|
exports.controlFlow = controlFlow;
|