spawn 0.1.0
spawn: ^0.1.0 copied to clipboard
Background execution for Dart that works everywhere - isolates on native, Web Workers on the web, one API. The missing web half of dart:isolate.
Changelog #
0.1.0 #
First release.
spawn(entry)starts a worker on an isolate (native) or a compiled Web Worker payload (web) behind one API, and completes only once the handler is running.Worker/WorkerClient:post,request, a broadcasteventsstream buffered until its first listener, graceful and forcedclose, andattach()for additional clients of one worker.WorkerChannel:messages,send,handleRequests,initialMessage,onClose.- One portability contract on every platform — the portable set, or
WireMessage— so a message that works on the VM works in a browser. - A documented 12-byte wire envelope with a
WireRegistry, andSpawnEntry.protocolto register a protocol's decoders on both ends. transfer:lists: a real move on the web, and a skipped copy on native for byte payloads.SpawnCaps.zeroCopyTransferreports which you got.SpawnServicelifetimes with pluggable, reference-countedServiceProviders and an error at spawn time that names the missing registration.spawnLocalruns a handler in process behind a realWorker, for tests and as the web debug fallback when a payload has not been built.dart run spawn:buildcompileslib/workers/*.dartto web payloads, with content-hash skipping. No code generation and no build_runner.JobEntryparses and validates;Jobs.enqueuethrows until deferred, OS-scheduled work lands.SpawnEntry.nativeis reserved for a C- or wasm-hosted worker and throws.PlatformValuecarries an opaque platform object - aVideoFrame,AudioData,ImageBitmap,OffscreenCanvas- through a channel untouched. It always transfers rather than clones, including from a request response, because most of those types cannot be cloned at all. This is what lets a decode worker hand finished frames to the main thread.spawn:buildskips files in the worker directory that declare nomain, so a worker can sit next to its conditional-import stubs and helpers, and its up-to-date check now covers path dependencies. A payload that ignored changes to a sibling package under active development is worse than no caching at all: the tests pass against code that is no longer there.