@effect/platform-browser 0.31.28 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/internal/runtime.js +1 -1
- package/dist/cjs/internal/runtime.js.map +1 -1
- package/dist/cjs/internal/workerRunner.js +77 -46
- package/dist/cjs/internal/workerRunner.js.map +1 -1
- package/dist/esm/internal/runtime.js +1 -1
- package/dist/esm/internal/runtime.js.map +1 -1
- package/dist/esm/internal/workerRunner.js +77 -46
- package/dist/esm/internal/workerRunner.js.map +1 -1
- package/package.json +4 -4
- package/src/internal/runtime.ts +1 -1
- package/src/internal/workerRunner.ts +68 -29
|
@@ -47,7 +47,7 @@ const runMain = (effect, options) => {
|
|
|
47
47
|
const _effect = useStructuredLogger(effect);
|
|
48
48
|
const fiber = Effect.runFork(options?.disableErrorReporting === true ? _effect : Effect.tapErrorCause(_effect, cause => {
|
|
49
49
|
if (Cause.isInterruptedOnly(cause)) {
|
|
50
|
-
return Effect.
|
|
50
|
+
return Effect.void;
|
|
51
51
|
}
|
|
52
52
|
return Effect.logError(cause);
|
|
53
53
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":["Cause","_interopRequireWildcard","require","Effect","FiberRef","HashSet","Logger","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","useStructuredLogger","locallyWith","currentLoggers","loggers","defaultLogger","remove","add","withConsoleLog","structuredLogger","runMain","effect","options","_effect","fiber","runFork","disableErrorReporting","tapErrorCause","cause","isInterruptedOnly","
|
|
1
|
+
{"version":3,"file":"runtime.js","names":["Cause","_interopRequireWildcard","require","Effect","FiberRef","HashSet","Logger","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","useStructuredLogger","locallyWith","currentLoggers","loggers","defaultLogger","remove","add","withConsoleLog","structuredLogger","runMain","effect","options","_effect","fiber","runFork","disableErrorReporting","tapErrorCause","cause","isInterruptedOnly","void","logError","addEventListener","unsafeInterruptAsFork","id","exports"],"sources":["../../../src/internal/runtime.ts"],"sourcesContent":[null],"mappings":";;;;;;AACA,IAAAA,KAAA,gBAAAC,uBAAA,eAAAC,OAAA;AACA,IAAAC,MAAA,gBAAAF,uBAAA,eAAAC,OAAA;AACA,IAAAE,QAAA,gBAAAH,uBAAA,eAAAC,OAAA;AACA,IAAAG,OAAA,gBAAAJ,uBAAA,eAAAC,OAAA;AACA,IAAAI,MAAA,gBAAAL,uBAAA,eAAAC,OAAA;AAAuC,SAAAK,yBAAAC,CAAA;EAAA,yBAAAC,OAAA;EAAA,IAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAF,wBAAA,YAAAA,CAAAC,CAAA;IAAA,OAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA;EAAA,GAAAF,CAAA;AAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAE,CAAA;EAAA,KAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA;EAAA,aAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA;IAAAK,OAAA,EAAAL;EAAA;EAAA,IAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA;EAAA,IAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA;EAAA,IAAAQ,CAAA;MAAAC,SAAA;IAAA;IAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA;EAAA,SAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA;IAAA,IAAAG,CAAA,GAAAP,CAAA,GAA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,CAACH,KAAK,CAAC;EAC/B,CAAC,CAAC,CACL;EAEDI,gBAAgB,CAAC,cAAc,EAAE,MAAK;IACpCR,KAAK,CAACS,qBAAqB,CAACT,KAAK,CAACU,EAAE,EAAE,CAAC;EACzC,CAAC,CAAC;AACJ,CAAC;AAAAC,OAAA,CAAAf,OAAA,GAAAA,OAAA","ignoreList":[]}
|
|
@@ -8,6 +8,8 @@ var _WorkerError = /*#__PURE__*/require("@effect/platform/WorkerError");
|
|
|
8
8
|
var Runner = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/WorkerRunner"));
|
|
9
9
|
var Cause = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Cause"));
|
|
10
10
|
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect"));
|
|
11
|
+
var FiberSet = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/FiberSet"));
|
|
12
|
+
var _GlobalValue = /*#__PURE__*/require("effect/GlobalValue");
|
|
11
13
|
var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer"));
|
|
12
14
|
var Queue = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Queue"));
|
|
13
15
|
var Schedule = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Schedule"));
|
|
@@ -36,59 +38,88 @@ function _interopRequireWildcard(e, r) {
|
|
|
36
38
|
}
|
|
37
39
|
return n.default = e, t && t.set(e, n), n;
|
|
38
40
|
}
|
|
41
|
+
const cachedPorts = /*#__PURE__*/(0, _GlobalValue.globalValue)("@effect/platform-browser/Worker/cachedPorts", () => new Set());
|
|
42
|
+
function globalHandleConnect(event) {
|
|
43
|
+
cachedPorts.add(event.ports[0]);
|
|
44
|
+
}
|
|
45
|
+
if ("onconnect" in self) {
|
|
46
|
+
self.onconnect = globalHandleConnect;
|
|
47
|
+
}
|
|
39
48
|
const platformRunnerImpl = /*#__PURE__*/Runner.PlatformRunner.of({
|
|
40
49
|
[Runner.PlatformRunnerTypeId]: Runner.PlatformRunnerTypeId,
|
|
41
50
|
start(shutdown) {
|
|
42
51
|
return Effect.gen(function* (_) {
|
|
43
|
-
|
|
44
|
-
self.addEventListener("connect", function (event) {
|
|
45
|
-
const port = event.ports[0];
|
|
46
|
-
port.start();
|
|
47
|
-
resume(Effect.succeed(port));
|
|
48
|
-
}, {
|
|
49
|
-
once: true,
|
|
50
|
-
signal
|
|
51
|
-
});
|
|
52
|
-
}));
|
|
52
|
+
let currentPortId = 0;
|
|
53
53
|
const queue = yield* _(Queue.unbounded());
|
|
54
|
-
yield* _(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
const runFork = yield* _(FiberSet.makeRuntime());
|
|
55
|
+
const ports = new Map();
|
|
56
|
+
const send = (portId, message, transfer) => Effect.sync(() => {
|
|
57
|
+
ports.get(portId)?.postMessage([1, message], {
|
|
58
|
+
transfer: transfer
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
function handlePort(port, sharedWorker) {
|
|
62
|
+
const portId = currentPortId++;
|
|
63
|
+
ports.set(portId, port);
|
|
64
|
+
Effect.async(resume => {
|
|
65
|
+
function onMessage(event) {
|
|
66
|
+
const message = event.data;
|
|
67
|
+
if (message[0] === 0) {
|
|
68
|
+
queue.unsafeOffer([portId, message[1]]);
|
|
69
|
+
} else if (sharedWorker) {
|
|
70
|
+
resume(Effect.interrupt);
|
|
71
|
+
} else {
|
|
72
|
+
Effect.runFork(shutdown);
|
|
73
|
+
}
|
|
61
74
|
}
|
|
75
|
+
function onMessageError(error) {
|
|
76
|
+
resume(new _WorkerError.WorkerError({
|
|
77
|
+
reason: "decode",
|
|
78
|
+
error: error.error ?? error.message
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
function onError(error) {
|
|
82
|
+
resume(new _WorkerError.WorkerError({
|
|
83
|
+
reason: "unknown",
|
|
84
|
+
error: error.error ?? error.message
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
port.addEventListener("message", onMessage);
|
|
88
|
+
port.addEventListener("messageerror", onMessageError);
|
|
89
|
+
port.addEventListener("error", onError);
|
|
90
|
+
// ready
|
|
91
|
+
if ("start" in port) {
|
|
92
|
+
port.start();
|
|
93
|
+
}
|
|
94
|
+
port.postMessage([0]);
|
|
95
|
+
return Effect.sync(() => {
|
|
96
|
+
port.removeEventListener("message", onMessage);
|
|
97
|
+
port.removeEventListener("messageerror", onMessageError);
|
|
98
|
+
port.removeEventListener("error", onError);
|
|
99
|
+
});
|
|
100
|
+
}).pipe(Effect.tapErrorCause(cause => Cause.isInterruptedOnly(cause) ? Effect.void : Effect.logDebug(cause)), Effect.retry(Schedule.forever), Effect.annotateLogs({
|
|
101
|
+
package: "@effect/platform-browser",
|
|
102
|
+
module: "WorkerRunner"
|
|
103
|
+
}), Effect.ensuring(Effect.sync(() => {
|
|
104
|
+
ports.delete(portId);
|
|
105
|
+
})), Effect.interruptible, runFork);
|
|
106
|
+
}
|
|
107
|
+
if ("onconnect" in self) {
|
|
108
|
+
self.onconnect = function (event) {
|
|
109
|
+
const port = event.ports[0];
|
|
110
|
+
handlePort(port, true);
|
|
111
|
+
};
|
|
112
|
+
yield* _(Effect.addFinalizer(() => Effect.sync(() => {
|
|
113
|
+
;
|
|
114
|
+
self.onconnect = globalHandleConnect;
|
|
115
|
+
})));
|
|
116
|
+
for (const port of cachedPorts) {
|
|
117
|
+
handlePort(port, true);
|
|
62
118
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
function onError(error) {
|
|
70
|
-
resume(new _WorkerError.WorkerError({
|
|
71
|
-
reason: "unknown",
|
|
72
|
-
error: error.error ?? error.message
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
port.addEventListener("message", onMessage);
|
|
76
|
-
port.addEventListener("messageerror", onMessageError);
|
|
77
|
-
port.addEventListener("error", onError);
|
|
78
|
-
return Effect.sync(() => {
|
|
79
|
-
port.removeEventListener("message", onMessage);
|
|
80
|
-
port.removeEventListener("messageerror", onMessageError);
|
|
81
|
-
port.removeEventListener("error", onError);
|
|
82
|
-
});
|
|
83
|
-
}), Effect.tapErrorCause(cause => Cause.isInterruptedOnly(cause) ? Effect.unit : Effect.logDebug(cause)), Effect.retry(Schedule.forever), Effect.annotateLogs({
|
|
84
|
-
package: "@effect/platform-browser",
|
|
85
|
-
module: "WorkerRunner"
|
|
86
|
-
}), Effect.interruptible, Effect.forkScoped);
|
|
87
|
-
const send = (message, transfer) => Effect.sync(() => port.postMessage([1, message], {
|
|
88
|
-
transfer: transfer
|
|
89
|
-
}));
|
|
90
|
-
// ready
|
|
91
|
-
port.postMessage([0]);
|
|
119
|
+
cachedPorts.clear();
|
|
120
|
+
} else {
|
|
121
|
+
handlePort(self, false);
|
|
122
|
+
}
|
|
92
123
|
return {
|
|
93
124
|
queue,
|
|
94
125
|
send
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerRunner.js","names":["_WorkerError","require","Runner","_interopRequireWildcard","Cause","Effect","Layer","Queue","Schedule","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","platformRunnerImpl","PlatformRunner","of","PlatformRunnerTypeId","start","shutdown","gen","_","
|
|
1
|
+
{"version":3,"file":"workerRunner.js","names":["_WorkerError","require","Runner","_interopRequireWildcard","Cause","Effect","FiberSet","_GlobalValue","Layer","Queue","Schedule","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","cachedPorts","globalValue","Set","globalHandleConnect","event","add","ports","self","onconnect","platformRunnerImpl","PlatformRunner","of","PlatformRunnerTypeId","start","shutdown","gen","_","currentPortId","queue","unbounded","runFork","makeRuntime","Map","send","portId","message","transfer","sync","postMessage","handlePort","port","sharedWorker","async","resume","onMessage","data","unsafeOffer","interrupt","onMessageError","error","WorkerError","reason","onError","addEventListener","removeEventListener","pipe","tapErrorCause","cause","isInterruptedOnly","void","logDebug","retry","forever","annotateLogs","package","module","ensuring","delete","interruptible","addFinalizer","clear","layer","exports","succeed"],"sources":["../../../src/internal/workerRunner.ts"],"sourcesContent":[null],"mappings":";;;;;;AAAA,IAAAA,YAAA,gBAAAC,OAAA;AACA,IAAAC,MAAA,gBAAAC,uBAAA,eAAAF,OAAA;AACA,IAAAG,KAAA,gBAAAD,uBAAA,eAAAF,OAAA;AACA,IAAAI,MAAA,gBAAAF,uBAAA,eAAAF,OAAA;AACA,IAAAK,QAAA,gBAAAH,uBAAA,eAAAF,OAAA;AACA,IAAAM,YAAA,gBAAAN,OAAA;AACA,IAAAO,KAAA,gBAAAL,uBAAA,eAAAF,OAAA;AACA,IAAAQ,KAAA,gBAAAN,uBAAA,eAAAF,OAAA;AACA,IAAAS,QAAA,gBAAAP,uBAAA,eAAAF,OAAA;AAA2C,SAAAU,yBAAAC,CAAA;EAAA,yBAAAC,OAAA;EAAA,IAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAF,wBAAA,YAAAA,CAAAC,CAAA;IAAA,OAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA;EAAA,GAAAF,CAAA;AAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAE,CAAA;EAAA,KAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA;EAAA,aAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA;IAAAK,OAAA,EAAAL;EAAA;EAAA,IAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA;EAAA,IAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,G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,CAAC,CAAC,CAAC,EACHlD,MAAM,CAACoF,aAAa,EACpBtC,OAAO,CACR;MACH;MAEA,IAAI,WAAW,IAAIb,IAAI,EAAE;QACvBA,IAAI,CAACC,SAAS,GAAG,UAASJ,KAAmB;UAC3C,MAAM0B,IAAI,GAAI1B,KAAsB,CAACE,KAAK,CAAC,CAAC,CAAC;UAC7CuB,UAAU,CAACC,IAAI,EAAE,IAAI,CAAC;QACxB,CAAC;QACD,OAAOd,CAAC,CAAC1C,MAAM,CAACqF,YAAY,CAAC,MAC3BrF,MAAM,CAACqD,IAAI,CAAC,MAAK;UACf;UAAEpB,IAAY,CAACC,SAAS,GAAGL,mBAAmB;QAChD,CAAC,CAAC,CACH,CAAC;QACF,KAAK,MAAM2B,IAAI,IAAI9B,WAAW,EAAE;UAC9B6B,UAAU,CAACC,IAAI,EAAE,IAAI,CAAC;QACxB;QACA9B,WAAW,CAAC4D,KAAK,EAAE;MACrB,CAAC,MAAM;QACL/B,UAAU,CAACtB,IAAW,EAAE,KAAK,CAAC;MAChC;MAEA,OAAO;QAAEW,KAAK;QAAEK;MAAI,CAAE;IACxB,CAAC,CAAC;EACJ;CACD,CAAC;AAEF;AACO,MAAMsC,KAAK,GAAAC,OAAA,CAAAD,KAAA,gBAAGpF,KAAK,CAACsF,OAAO,CAAC5F,MAAM,CAACuC,cAAc,EAAED,kBAAkB,CAAC","ignoreList":[]}
|
|
@@ -16,7 +16,7 @@ export const runMain = (effect, options) => {
|
|
|
16
16
|
const _effect = useStructuredLogger(effect);
|
|
17
17
|
const fiber = Effect.runFork(options?.disableErrorReporting === true ? _effect : Effect.tapErrorCause(_effect, cause => {
|
|
18
18
|
if (Cause.isInterruptedOnly(cause)) {
|
|
19
|
-
return Effect.
|
|
19
|
+
return Effect.void;
|
|
20
20
|
}
|
|
21
21
|
return Effect.logError(cause);
|
|
22
22
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":["Cause","Effect","FiberRef","HashSet","Logger","useStructuredLogger","locallyWith","currentLoggers","loggers","has","defaultLogger","set","remove","add","withConsoleLog","structuredLogger","runMain","effect","options","_effect","fiber","runFork","disableErrorReporting","tapErrorCause","cause","isInterruptedOnly","
|
|
1
|
+
{"version":3,"file":"runtime.js","names":["Cause","Effect","FiberRef","HashSet","Logger","useStructuredLogger","locallyWith","currentLoggers","loggers","has","defaultLogger","set","remove","add","withConsoleLog","structuredLogger","runMain","effect","options","_effect","fiber","runFork","disableErrorReporting","tapErrorCause","cause","isInterruptedOnly","void","logError","addEventListener","unsafeInterruptAsFork","id"],"sources":["../../../src/internal/runtime.ts"],"sourcesContent":[null],"mappings":"AACA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC;AACA,MAAMC,mBAAmB,gBAAGJ,MAAM,CAACK,WAAW,CAACJ,QAAQ,CAACK,cAAc,EAAGC,OAAO,IAAI;EAClF,IAAIL,OAAO,CAACM,GAAG,CAACD,OAAO,EAAEJ,MAAM,CAACM,aAAa,CAAC,EAAE;IAC9C,MAAMC,GAAG,GAAGR,OAAO,CAACS,MAAM,CAACJ,OAAO,EAAEJ,MAAM,CAACM,aAAa,CAAC;IACzD,OAAOP,OAAO,CAACU,GAAG,CAACF,GAAG,EAAEP,MAAM,CAACU,cAAc,CAACV,MAAM,CAACW,gBAAgB,CAAC,CAAC;EACzE;EAEA,OAAOP,OAAO;AAChB,CAAC,CAAC;AAEF;AACA,OAAO,MAAMQ,OAAO,GAAYA,CAC9BC,MAAM,EACNC,OAAO,KACL;EACF,MAAMC,OAAO,GAAGd,mBAAmB,CAACY,MAAM,CAAC;EAE3C,MAAMG,KAAK,GAAGnB,MAAM,CAACoB,OAAO,CAC1BH,OAAO,EAAEI,qBAAqB,KAAK,IAAI,GACrCH,OAAO,GACPlB,MAAM,CAACsB,aAAa,CAACJ,OAAO,EAAGK,KAAK,IAAI;IACtC,IAAIxB,KAAK,CAACyB,iBAAiB,CAACD,KAAK,CAAC,EAAE;MAClC,OAAOvB,MAAM,CAACyB,IAAI;IACpB;IACA,OAAOzB,MAAM,CAAC0B,QAAQ,CAACH,KAAK,CAAC;EAC/B,CAAC,CAAC,CACL;EAEDI,gBAAgB,CAAC,cAAc,EAAE,MAAK;IACpCR,KAAK,CAACS,qBAAqB,CAACT,KAAK,CAACU,EAAE,EAAE,CAAC;EACzC,CAAC,CAAC;AACJ,CAAC","ignoreList":[]}
|
|
@@ -2,62 +2,93 @@ import { WorkerError } from "@effect/platform/WorkerError";
|
|
|
2
2
|
import * as Runner from "@effect/platform/WorkerRunner";
|
|
3
3
|
import * as Cause from "effect/Cause";
|
|
4
4
|
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as FiberSet from "effect/FiberSet";
|
|
6
|
+
import { globalValue } from "effect/GlobalValue";
|
|
5
7
|
import * as Layer from "effect/Layer";
|
|
6
8
|
import * as Queue from "effect/Queue";
|
|
7
9
|
import * as Schedule from "effect/Schedule";
|
|
10
|
+
const cachedPorts = /*#__PURE__*/globalValue("@effect/platform-browser/Worker/cachedPorts", () => new Set());
|
|
11
|
+
function globalHandleConnect(event) {
|
|
12
|
+
cachedPorts.add(event.ports[0]);
|
|
13
|
+
}
|
|
14
|
+
if ("onconnect" in self) {
|
|
15
|
+
self.onconnect = globalHandleConnect;
|
|
16
|
+
}
|
|
8
17
|
const platformRunnerImpl = /*#__PURE__*/Runner.PlatformRunner.of({
|
|
9
18
|
[Runner.PlatformRunnerTypeId]: Runner.PlatformRunnerTypeId,
|
|
10
19
|
start(shutdown) {
|
|
11
20
|
return Effect.gen(function* (_) {
|
|
12
|
-
|
|
13
|
-
self.addEventListener("connect", function (event) {
|
|
14
|
-
const port = event.ports[0];
|
|
15
|
-
port.start();
|
|
16
|
-
resume(Effect.succeed(port));
|
|
17
|
-
}, {
|
|
18
|
-
once: true,
|
|
19
|
-
signal
|
|
20
|
-
});
|
|
21
|
-
}));
|
|
21
|
+
let currentPortId = 0;
|
|
22
22
|
const queue = yield* _(Queue.unbounded());
|
|
23
|
-
yield* _(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const runFork = yield* _(FiberSet.makeRuntime());
|
|
24
|
+
const ports = new Map();
|
|
25
|
+
const send = (portId, message, transfer) => Effect.sync(() => {
|
|
26
|
+
ports.get(portId)?.postMessage([1, message], {
|
|
27
|
+
transfer: transfer
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
function handlePort(port, sharedWorker) {
|
|
31
|
+
const portId = currentPortId++;
|
|
32
|
+
ports.set(portId, port);
|
|
33
|
+
Effect.async(resume => {
|
|
34
|
+
function onMessage(event) {
|
|
35
|
+
const message = event.data;
|
|
36
|
+
if (message[0] === 0) {
|
|
37
|
+
queue.unsafeOffer([portId, message[1]]);
|
|
38
|
+
} else if (sharedWorker) {
|
|
39
|
+
resume(Effect.interrupt);
|
|
40
|
+
} else {
|
|
41
|
+
Effect.runFork(shutdown);
|
|
42
|
+
}
|
|
30
43
|
}
|
|
44
|
+
function onMessageError(error) {
|
|
45
|
+
resume(new WorkerError({
|
|
46
|
+
reason: "decode",
|
|
47
|
+
error: error.error ?? error.message
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
function onError(error) {
|
|
51
|
+
resume(new WorkerError({
|
|
52
|
+
reason: "unknown",
|
|
53
|
+
error: error.error ?? error.message
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
port.addEventListener("message", onMessage);
|
|
57
|
+
port.addEventListener("messageerror", onMessageError);
|
|
58
|
+
port.addEventListener("error", onError);
|
|
59
|
+
// ready
|
|
60
|
+
if ("start" in port) {
|
|
61
|
+
port.start();
|
|
62
|
+
}
|
|
63
|
+
port.postMessage([0]);
|
|
64
|
+
return Effect.sync(() => {
|
|
65
|
+
port.removeEventListener("message", onMessage);
|
|
66
|
+
port.removeEventListener("messageerror", onMessageError);
|
|
67
|
+
port.removeEventListener("error", onError);
|
|
68
|
+
});
|
|
69
|
+
}).pipe(Effect.tapErrorCause(cause => Cause.isInterruptedOnly(cause) ? Effect.void : Effect.logDebug(cause)), Effect.retry(Schedule.forever), Effect.annotateLogs({
|
|
70
|
+
package: "@effect/platform-browser",
|
|
71
|
+
module: "WorkerRunner"
|
|
72
|
+
}), Effect.ensuring(Effect.sync(() => {
|
|
73
|
+
ports.delete(portId);
|
|
74
|
+
})), Effect.interruptible, runFork);
|
|
75
|
+
}
|
|
76
|
+
if ("onconnect" in self) {
|
|
77
|
+
self.onconnect = function (event) {
|
|
78
|
+
const port = event.ports[0];
|
|
79
|
+
handlePort(port, true);
|
|
80
|
+
};
|
|
81
|
+
yield* _(Effect.addFinalizer(() => Effect.sync(() => {
|
|
82
|
+
;
|
|
83
|
+
self.onconnect = globalHandleConnect;
|
|
84
|
+
})));
|
|
85
|
+
for (const port of cachedPorts) {
|
|
86
|
+
handlePort(port, true);
|
|
31
87
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
function onError(error) {
|
|
39
|
-
resume(new WorkerError({
|
|
40
|
-
reason: "unknown",
|
|
41
|
-
error: error.error ?? error.message
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
port.addEventListener("message", onMessage);
|
|
45
|
-
port.addEventListener("messageerror", onMessageError);
|
|
46
|
-
port.addEventListener("error", onError);
|
|
47
|
-
return Effect.sync(() => {
|
|
48
|
-
port.removeEventListener("message", onMessage);
|
|
49
|
-
port.removeEventListener("messageerror", onMessageError);
|
|
50
|
-
port.removeEventListener("error", onError);
|
|
51
|
-
});
|
|
52
|
-
}), Effect.tapErrorCause(cause => Cause.isInterruptedOnly(cause) ? Effect.unit : Effect.logDebug(cause)), Effect.retry(Schedule.forever), Effect.annotateLogs({
|
|
53
|
-
package: "@effect/platform-browser",
|
|
54
|
-
module: "WorkerRunner"
|
|
55
|
-
}), Effect.interruptible, Effect.forkScoped);
|
|
56
|
-
const send = (message, transfer) => Effect.sync(() => port.postMessage([1, message], {
|
|
57
|
-
transfer: transfer
|
|
58
|
-
}));
|
|
59
|
-
// ready
|
|
60
|
-
port.postMessage([0]);
|
|
88
|
+
cachedPorts.clear();
|
|
89
|
+
} else {
|
|
90
|
+
handlePort(self, false);
|
|
91
|
+
}
|
|
61
92
|
return {
|
|
62
93
|
queue,
|
|
63
94
|
send
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerRunner.js","names":["WorkerError","Runner","Cause","Effect","Layer","Queue","Schedule","platformRunnerImpl","PlatformRunner","of","PlatformRunnerTypeId","start","shutdown","gen","_","
|
|
1
|
+
{"version":3,"file":"workerRunner.js","names":["WorkerError","Runner","Cause","Effect","FiberSet","globalValue","Layer","Queue","Schedule","cachedPorts","Set","globalHandleConnect","event","add","ports","self","onconnect","platformRunnerImpl","PlatformRunner","of","PlatformRunnerTypeId","start","shutdown","gen","_","currentPortId","queue","unbounded","runFork","makeRuntime","Map","send","portId","message","transfer","sync","get","postMessage","handlePort","port","sharedWorker","set","async","resume","onMessage","data","unsafeOffer","interrupt","onMessageError","error","reason","onError","addEventListener","removeEventListener","pipe","tapErrorCause","cause","isInterruptedOnly","void","logDebug","retry","forever","annotateLogs","package","module","ensuring","delete","interruptible","addFinalizer","clear","layer","succeed"],"sources":["../../../src/internal/workerRunner.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,WAAW,QAAQ,8BAA8B;AAC1D,OAAO,KAAKC,MAAM,MAAM,+BAA+B;AACvD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,SAASC,WAAW,QAAQ,oBAAoB;AA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CAAC,MAAM;QACL/B,UAAU,CAACvB,IAAW,EAAE,KAAK,CAAC;MAChC;MAEA,OAAO;QAAEW,KAAK;QAAEK;MAAI,CAAE;IACxB,CAAC,CAAC;EACJ;CACD,CAAC;AAEF;AACA,OAAO,MAAMuC,KAAK,gBAAGhE,KAAK,CAACiE,OAAO,CAACtE,MAAM,CAACiB,cAAc,EAAED,kBAAkB,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect/platform-browser",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.32.0",
|
|
4
|
+
"description": "Platform specific implementations for the browser",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"multipasta": "^0.2.0"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
|
-
"@effect/platform": "^0.
|
|
17
|
-
"effect": "^
|
|
16
|
+
"@effect/platform": "^0.49.0",
|
|
17
|
+
"effect": "^3.0.0"
|
|
18
18
|
},
|
|
19
19
|
"main": "./dist/cjs/index.js",
|
|
20
20
|
"module": "./dist/esm/index.js",
|
package/src/internal/runtime.ts
CHANGED
|
@@ -2,30 +2,47 @@ import { WorkerError } from "@effect/platform/WorkerError"
|
|
|
2
2
|
import * as Runner from "@effect/platform/WorkerRunner"
|
|
3
3
|
import * as Cause from "effect/Cause"
|
|
4
4
|
import * as Effect from "effect/Effect"
|
|
5
|
+
import * as FiberSet from "effect/FiberSet"
|
|
6
|
+
import { globalValue } from "effect/GlobalValue"
|
|
5
7
|
import * as Layer from "effect/Layer"
|
|
6
8
|
import * as Queue from "effect/Queue"
|
|
7
9
|
import * as Schedule from "effect/Schedule"
|
|
8
10
|
|
|
11
|
+
const cachedPorts = globalValue("@effect/platform-browser/Worker/cachedPorts", () => new Set<MessagePort>())
|
|
12
|
+
function globalHandleConnect(event: MessageEvent) {
|
|
13
|
+
cachedPorts.add((event as MessageEvent).ports[0])
|
|
14
|
+
}
|
|
15
|
+
if ("onconnect" in self) {
|
|
16
|
+
self.onconnect = globalHandleConnect
|
|
17
|
+
}
|
|
18
|
+
|
|
9
19
|
const platformRunnerImpl = Runner.PlatformRunner.of({
|
|
10
20
|
[Runner.PlatformRunnerTypeId]: Runner.PlatformRunnerTypeId,
|
|
11
21
|
start<I, O>(shutdown: Effect.Effect<void>) {
|
|
12
22
|
return Effect.gen(function*(_) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
let currentPortId = 0
|
|
24
|
+
|
|
25
|
+
const queue = yield* _(Queue.unbounded<readonly [portId: number, message: I]>())
|
|
26
|
+
const runFork = yield* _(FiberSet.makeRuntime<never>())
|
|
27
|
+
const ports = new Map<number, MessagePort>()
|
|
28
|
+
const send = (portId: number, message: O, transfer?: ReadonlyArray<unknown>) =>
|
|
29
|
+
Effect.sync(() => {
|
|
30
|
+
ports.get(portId)?.postMessage([1, message], {
|
|
31
|
+
transfer: transfer as any
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
function handlePort(port: MessagePort, sharedWorker: boolean) {
|
|
36
|
+
const portId = currentPortId++
|
|
37
|
+
ports.set(portId, port)
|
|
38
|
+
|
|
24
39
|
Effect.async<never, WorkerError, never>((resume) => {
|
|
25
40
|
function onMessage(event: MessageEvent) {
|
|
26
41
|
const message = (event as MessageEvent).data as Runner.BackingRunner.Message<I>
|
|
27
42
|
if (message[0] === 0) {
|
|
28
|
-
queue.unsafeOffer(message[1])
|
|
43
|
+
queue.unsafeOffer([portId, message[1]])
|
|
44
|
+
} else if (sharedWorker) {
|
|
45
|
+
resume(Effect.interrupt)
|
|
29
46
|
} else {
|
|
30
47
|
Effect.runFork(shutdown)
|
|
31
48
|
}
|
|
@@ -39,29 +56,51 @@ const platformRunnerImpl = Runner.PlatformRunner.of({
|
|
|
39
56
|
port.addEventListener("message", onMessage as any)
|
|
40
57
|
port.addEventListener("messageerror", onMessageError as any)
|
|
41
58
|
port.addEventListener("error", onError as any)
|
|
59
|
+
|
|
60
|
+
// ready
|
|
61
|
+
if ("start" in port) {
|
|
62
|
+
port.start()
|
|
63
|
+
}
|
|
64
|
+
port.postMessage([0])
|
|
65
|
+
|
|
42
66
|
return Effect.sync(() => {
|
|
43
67
|
port.removeEventListener("message", onMessage as any)
|
|
44
68
|
port.removeEventListener("messageerror", onMessageError as any)
|
|
45
69
|
port.removeEventListener("error", onError as any)
|
|
46
70
|
})
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
port.postMessage([1, message], {
|
|
60
|
-
transfer: transfer as any
|
|
61
|
-
})
|
|
71
|
+
}).pipe(
|
|
72
|
+
Effect.tapErrorCause((cause) => Cause.isInterruptedOnly(cause) ? Effect.void : Effect.logDebug(cause)),
|
|
73
|
+
Effect.retry(Schedule.forever),
|
|
74
|
+
Effect.annotateLogs({
|
|
75
|
+
package: "@effect/platform-browser",
|
|
76
|
+
module: "WorkerRunner"
|
|
77
|
+
}),
|
|
78
|
+
Effect.ensuring(Effect.sync(() => {
|
|
79
|
+
ports.delete(portId)
|
|
80
|
+
})),
|
|
81
|
+
Effect.interruptible,
|
|
82
|
+
runFork
|
|
62
83
|
)
|
|
63
|
-
|
|
64
|
-
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ("onconnect" in self) {
|
|
87
|
+
self.onconnect = function(event: MessageEvent) {
|
|
88
|
+
const port = (event as MessageEvent).ports[0]
|
|
89
|
+
handlePort(port, true)
|
|
90
|
+
}
|
|
91
|
+
yield* _(Effect.addFinalizer(() =>
|
|
92
|
+
Effect.sync(() => {
|
|
93
|
+
;(self as any).onconnect = globalHandleConnect
|
|
94
|
+
})
|
|
95
|
+
))
|
|
96
|
+
for (const port of cachedPorts) {
|
|
97
|
+
handlePort(port, true)
|
|
98
|
+
}
|
|
99
|
+
cachedPorts.clear()
|
|
100
|
+
} else {
|
|
101
|
+
handlePort(self as any, false)
|
|
102
|
+
}
|
|
103
|
+
|
|
65
104
|
return { queue, send }
|
|
66
105
|
})
|
|
67
106
|
}
|