The worker to communicate with. Can be a Worker instance, a URL, or a URL string.
Optionaloptions: ConnectSyncChannelOptionsOptional configuration options for the sync channel.
A promise that resolves with an AsyncIOResult containing the SharedArrayBuffer when the worker is ready.
The returned buffer can be shared with other contexts (e.g., iframes) via postMessage.
// Connect to worker and get SharedArrayBuffer
const result = await SyncChannel.connect(
new URL('./worker.js', import.meta.url),
{ sharedBufferLength: 1024 * 1024, opTimeout: 5000 }
);
result.inspect(sharedBuffer => {
// Share with iframe
iframe.contentWindow.postMessage({ sharedBuffer }, '*');
});
Connects to a worker and establishes a sync channel for synchronous file system operations. Must be called before using any sync API functions.