From 955355405f83995d466244960858f9715e217856 Mon Sep 17 00:00:00 2001 From: Davor Hrg Date: Mon, 11 Mar 2024 23:39:24 +0100 Subject: [PATCH] withTransferable --- packages/postmessage/README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/postmessage/README.md b/packages/postmessage/README.md index 6bb7f30..0c4892d 100644 --- a/packages/postmessage/README.md +++ b/packages/postmessage/README.md @@ -83,13 +83,15 @@ const result = await workerApi.runScript({ script}) // result is now known to be ScriptResponse and you get autocomplete ``` - - - ## transferable It is simple to send transferable objects when sending a message to the worker by adding a parameter to `postMessage`. It is however more tricky to support transferable for return values without complicating simple use cases that do not need transferable. If you have a method that can be called and it needs to return transferable then you must use object as a return value. -When returning such object, include `__transferable` key in the return value. It will not be in the data at the receiving end but will be taken out and passed to postMessage as a transferable parameter. +When returning such object in call to `withTransferable` before returning the value. +It will not be in the data at the receiving end, but will be taken out and passed to postMessage as the transferable parameter. + +```js + return withTransferable({ entities, mainTime }, transferable) +```