UNPKG

1.81 kBTypeScriptView Raw
1import { $transferable } from "./symbols";
2export interface TransferDescriptor<T = any> {
3 [$transferable]: true;
4 send: T;
5 transferables: Transferable[];
6}
7export declare function isTransferDescriptor(thing: any): thing is TransferDescriptor;
8/**
9 * Mark a transferable object as such, so it will no be serialized and
10 * deserialized on messaging with the main thread, but to transfer
11 * ownership of it to the receiving thread.
12 *
13 * Only works with array buffers, message ports and few more special
14 * types of objects, but it's much faster than serializing and
15 * deserializing them.
16 *
17 * Note:
18 * The transferable object cannot be accessed by this thread again
19 * unless the receiving thread transfers it back again!
20 *
21 * @param transferable Array buffer, message port or similar.
22 * @see <https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast>
23 */
24export declare function Transfer(transferable: Transferable): TransferDescriptor;
25/**
26 * Mark transferable objects within an arbitrary object or array as
27 * being a transferable object. They will then not be serialized
28 * and deserialized on messaging with the main thread, but ownership
29 * of them will be tranferred to the receiving thread.
30 *
31 * Only array buffers, message ports and few more special types of
32 * objects can be transferred, but it's much faster than serializing and
33 * deserializing them.
34 *
35 * Note:
36 * The transferable object cannot be accessed by this thread again
37 * unless the receiving thread transfers it back again!
38 *
39 * @param transferable Array buffer, message port or similar.
40 * @see <https://developers.google.com/web/updates/2011/12/Transferable-Objects-Lightning-Fast>
41 */
42export declare function Transfer<T>(payload: T, transferables: Transferable[]): TransferDescriptor;