The SharedArrayBuffer received from another context.
Optionaloptions: AttachSyncChannelOptionsOptional configuration options.
A VoidIOResult indicating success or failure.
// In iframe: receive SharedArrayBuffer from main page
window.addEventListener('message', (event) => {
if (event.data.sharedBuffer) {
const result = SyncChannel.attach(event.data.sharedBuffer, { opTimeout: 5000 });
if (result.isOk()) {
// Now sync APIs can be used
const fileResult = readTextFileSync('/data/file.txt');
}
}
});
Attaches to an existing
SharedArrayBufferfor synchronous file system operations. Used to share a sync channel connection with other contexts (e.g., iframes).After calling this function, sync APIs (e.g.,
readFileSync,writeFileSync) can be used in the current context without callingconnect.