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);
if (typeof result !== "undefined") {
if (!isIterable(result)) result = [result];
for (const p of result) {
postMessage(typeof p !== "object" ? p : Object.assign(p, {_time: performance.now() - t0}));
}
close();
}
}`;
}