Skip to content

Commit

Permalink
Clean up and comment data URI implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed May 15, 2018
1 parent a7ab747 commit 371d10c
Showing 1 changed file with 2 additions and 31 deletions.
33 changes: 2 additions & 31 deletions greenlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export default function greenlet(asyncFunction) {

// Create an "inline" worker (1:1 at definition time)
const worker = new Worker(
// Use a data URI for the worker's src. It inlines the target function and an RPC handler:
'data:,$$='+asyncFunction+';onmessage='+(e => {
/* global $$ */

// Invoking within then() captures exceptions in userFunc() as rejections
// Invoking within then() captures exceptions in the supplied async function as rejections
Promise.resolve().then(
$$.bind.apply($$, e.data)
).then(
Expand All @@ -31,36 +32,6 @@ export default function greenlet(asyncFunction) {
er => { postMessage([e.data[0], 1, '' + er]); }
);
})

/*
// The URL is a pointer to a stringified function (as a blob object)
URL.createObjectURL(
new Blob([
'$$=', asyncFunction,
// Register our wrapper function as the message handler
';onmessage=',
// userFunc() is the user-supplied async function
e => {
// Invoking within then() captures exceptions in userFunc() as rejections
Promise.resolve().then(
$$.bind.apply($$, e.data)
).then(
// success handler - callback(id, SUCCESS(0), result)
// if `d` is transferable transfer zero-copy
d => {
postMessage([e.data[0], 0, d], [d].filter(x => (
(x instanceof ArrayBuffer) ||
(x instanceof MessagePort) ||
(x instanceof ImageBitmap)
)));
},
// error handler - callback(id, ERROR(1), error)
er => { postMessage([e.data[0], 1, '' + er]); }
);
}
])
)
*/
);

/** Handle RPC results/errors coming back out of the worker.
Expand Down

0 comments on commit 371d10c

Please sign in to comment.