@xylabs/threads
Version:
Web workers & worker threads as simple as a function call
49 lines • 2.13 kB
TypeScript
import { $transferable } from './symbols.ts';
/** Descriptor wrapping a value with its associated transferable objects for zero-copy messaging. */
export interface TransferDescriptor<T = any> {
[$transferable]: true;
send: T;
transferables: Transferable[];
}
/**
* Check whether a value is a `TransferDescriptor` created by `Transfer()`.
* @param thing - The value to check.
* @returns True if the value is a transfer descriptor.
*/
export declare function isTransferDescriptor(thing: any): thing is TransferDescriptor;
/**
* Mark a transferable object as such, so it will no be serialized and
* deserialized on messaging with the main thread, but to transfer
* ownership of it to the receiving thread.
*
* Only works with array buffers, message ports and few more special
* types of objects, but it's much faster than serializing and
* deserializing them.
*
* Note:
* The transferable object cannot be accessed by this thread again
* unless the receiving thread transfers it back again!
*
* @param transferable Array buffer, message port or similar.
* @see <https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast>
*/
export declare function Transfer(transferable: Transferable): TransferDescriptor;
/**
* Mark transferable objects within an arbitrary object or array as
* being a transferable object. They will then not be serialized
* and deserialized on messaging with the main thread, but ownership
* of them will be tranferred to the receiving thread.
*
* Only array buffers, message ports and few more special types of
* objects can be transferred, but it's much faster than serializing and
* deserializing them.
*
* Note:
* The transferable object cannot be accessed by this thread again
* unless the receiving thread transfers it back again!
*
* @param transferable Array buffer, message port or similar.
* @see <https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast>
*/
export declare function Transfer<T>(payload: T, transferables: Transferable[]): TransferDescriptor;
//# sourceMappingURL=transferable.d.ts.map