w3ctag / design-principles

A small-but-growing set of design principles collected by the TAG while reviewing specifications
https://w3ctag.github.io/design-principles
173 stars 46 forks source link

Create advice for how to handover access to sensors and devices on dedicated workers #112

Open kenchris opened 5 years ago

kenchris commented 5 years ago

Permission and choosing devices happens on the main thread so in order to work with these "objects" on a dedicated worker, the access somehow has to be handed over.

Document the best way of doing this

dbaron commented 5 years ago

This was related to the feedback given in w3ctag/design-reviews#277. I think the issue there was that specs that can be used on multiple threads ought to describe what their model for threadsafety is (e.g., exclusive access to what, at what points).

kenchris commented 5 years ago

I am with you on that @dbaron but it also affects other things, like today Bluetooth and USB devices are requested which pops up a dialog and you get access to a handle. With sensors, you construct them and there are currently no permission prompt

@reillyeon @anssik

torgo commented 4 years ago

We discussed on breakout 31-march and agreed to put it on the back burner for now.

cynthia commented 3 years ago

I'm a bit skeptical about the design choices made in w3ctag/design-reviews#277.

The pattern here is unique to this use-case, and it's unclear how it works with regard to using the device from both the worker and the main thread since there is no explicit ownership transfer. It feels like our recommendation should be around the pattern that transferable streams uses, which transfers the entire object over postMessage, at which point the object on the main thread is considered dead as the ownership has been transferred over to the worker. Whether or not this is technically possible given the underlying implementation details is something we should solicit implementer feedback on though.

If this sounds reasonable I can draft up something.