WebAssembly / WebAssembly/threads

Common JS shell infrastructure

Open
#52 10 comments 0 reactions 1 assignee View on GitHub

@lars-t-hansen is already working on this.

Since Nov 6, 2017.

Dominant language
WebAssembly
Stars
767
Forks
54
PR merge metrics
No merged PRs in 30d

Description

cc @jfbastien @saambarati @kmiller68 @binji @MikeHolman

JF brought up the issue that we'll want a shared system in the JS shells to be able to test wasm threaded code. (And JS code for that matter - everyone will love us.)

To kick us off, I propose the following strawman:

The main thread can create new workers:

var w = new Worker(text)  // where text is defined below
w.postMessage(obj)           // what you think
w.onmessage = function (ev) { ... } // where ev.data is something sent by postMessage
dispatch()                           // enter the event loop

The worker can then:

onmessage = function (ev) { ... } where ev.data is something sent by postMessage
postMessage(obj)       // what you think

Note,

  • There is an implicit event loop in the worker.
  • There is an explicit event loop in the main thread by means of dispatch(); when it returns the main thread continues and may exit. (Debatable how good this explicit event loop is, not sure what d8 does here. Discuss.)
  • The worker cannot create new workers (keeps things simple).
  • The object to be posted is anything structured-cloneable
  • I haven't bothered to worry about transfering objects here

The "text" for a worker is a string that starts with 'text/plain;', this is for web compat so that tests can just carry over (ideally).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.