sycamore x futures

2022-03-29 ยท 2 min read

Can use gloo / gloo_timers crate for web-compatible futures. For example, gloo_timers::sleep(duration) -> TimeoutFuture.

Spawn a future on the current thread. Must be 'static and so can't contain any ScopeRefs or w/e:


Spawn a !Send future (which can contain ScopeRefs) using ctx.spawn_future:

use sycamore::futures::ScopeSpawnFuture;


Convert a Future<U> to a Signal<U> using ctx.create_resource:

use sycamore::futures::ScopeFuturesExt;


Web Workers #

Like threads for browser (but worse lol). No shared memory allowed; only serialized message passing. Workers can't manipulate the DOM.

  1. SharedWorkers (also "Public" workers) are a special kind of worker that can be accessed from multiple browser windows, tabs, or other workers. There can only exist one instance at a time.
  2. "Private" workers can be fired up and down at-will. Good for farming out work.

Communicating with workers:

  1. Bridges allow bidi comms b/w worker and component (or other workers).
  2. Dispatchers allow uni comms from component to worker.