1 | import { $transferable } from "./symbols";
|
2 | function isTransferable(thing) {
|
3 | if (!thing || typeof thing !== "object")
|
4 | return false;
|
5 |
|
6 | return true;
|
7 | }
|
8 | export function isTransferDescriptor(thing) {
|
9 | return thing && typeof thing === "object" && thing[$transferable];
|
10 | }
|
11 | export function Transfer(payload, transferables) {
|
12 | if (!transferables) {
|
13 | if (!isTransferable(payload))
|
14 | throw Error();
|
15 | transferables = [payload];
|
16 | }
|
17 | return {
|
18 | [$transferable]: true,
|
19 | send: payload,
|
20 | transferables
|
21 | };
|
22 | }
|