function workertext(f, preamble = "") {
return `
${preamble}
function isIterable(obj) {
return (
typeof obj[Symbol.iterator] === "function" &&
typeof obj["next"] == "function"
);
}
const __run__ = ${typeof f === "function" ? function_stringify(f) : f};
self.onmessage = async function(e) {
const t0 = performance.now();
let result = await __run__(e.data);
const postHelper = p =>
postMessage(
typeof p !== "object" || !Object.isExtensible(p) ?
p :
Object.assign(p, {_time: performance.now() - t0})
);
if (typeof result[Symbol.asyncIterator] === "function") {
for await (const p of result) {
postHelper(p);
}
close();
}
if (typeof result !== "undefined") {
if (!isIterable(result)) result = [result];
for (const p of result) {
postHelper(p);
}
close();
}
}`;
}