@lvce-editor/ipc 2.0.0 → 3.0.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/README.md +1 -1
- package/dist/index.js +831 -7
- package/package.json +2 -2
- package/dist/parts/Assert/Assert.js +0 -1
- package/dist/parts/CamelCase/CamelCase.js +0 -11
- package/dist/parts/Character/Character.js +0 -12
- package/dist/parts/ErrorCodes/ErrorCodes.js +0 -22
- package/dist/parts/FirstNodeWorkerEventType/FirstNodeWorkerEventType.js +0 -3
- package/dist/parts/FirstWebSocketEventType/FirstWebSocketEventType.js +0 -2
- package/dist/parts/FormatUtilityProcessName/FormatUtilityProcessName.js +0 -5
- package/dist/parts/GetFirstEvent/GetFirstEvent.js +0 -23
- package/dist/parts/GetFirstNodeChildProcessEvent/GetFirstNodeChildProcessEvent.js +0 -41
- package/dist/parts/GetFirstNodeWorkerEvent/GetFirstNodeWorkerEvent.js +0 -9
- package/dist/parts/GetFirstUtilityProcessEvent/GetFirstUtilityProcessEvent.js +0 -42
- package/dist/parts/GetFirstWebSocketEvent/GetFirstWebSocketEvent.js +0 -25
- package/dist/parts/GetHelpfulChildProcessError/GetHelpfulChildProcessError.js +0 -119
- package/dist/parts/GetUtilityProcessPortData/GetUtilityProcessPortData.js +0 -10
- package/dist/parts/IpcChildWithElectronMessagePort/IpcChildWithElectronMessagePort.js +0 -51
- package/dist/parts/IpcChildWithElectronUtilityProcess/IpcChildWithElectronUtilityProcess.js +0 -45
- package/dist/parts/IpcChildWithNodeForkedProcess/IpcChildWithNodeForkedProcess.js +0 -46
- package/dist/parts/IpcChildWithWebSocket/IpcChildWithWebSocket.js +0 -59
- package/dist/parts/IpcError/IpcError.js +0 -20
- package/dist/parts/IpcParentWithElectronUtilityProcess/IpcParentWithElectronUtilityProcess.js +0 -43
- package/dist/parts/IpcParentWithNodeForkedProcess/IpcParentWithNodeForkedProcess.js +0 -37
- package/dist/parts/IpcParentWithNodeWorker/IpcParentWithNodeWorker.js +0 -49
- package/dist/parts/IsMessagePortMain/IsMessagePortMain.js +0 -3
- package/dist/parts/IsWebSocketOpen/IsWebSocketOpen.js +0 -5
- package/dist/parts/JoinLines/JoinLines.js +0 -5
- package/dist/parts/Promises/Promises.js +0 -19
- package/dist/parts/SplitLines/SplitLines.js +0 -5
- package/dist/parts/VError/VError.js +0 -1
- package/dist/parts/WebSocketReadyState/WebSocketReadyState.js +0 -5
- package/dist/parts/WebSocketSerialization/WebSocketSerialization.js +0 -7
- package/dist/parts/WebSocketServer/WebSocketServer.js +0 -1
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Worker } from 'node:worker_threads'
|
|
2
|
-
import * as Assert from '../Assert/Assert.js'
|
|
3
|
-
import * as FirstNodeWorkerEventType from '../FirstNodeWorkerEventType/FirstNodeWorkerEventType.js'
|
|
4
|
-
import * as GetFirstNodeWorkerEvent from '../GetFirstNodeWorkerEvent/GetFirstNodeWorkerEvent.js'
|
|
5
|
-
import { IpcError } from '../IpcError/IpcError.js'
|
|
6
|
-
|
|
7
|
-
export const create = async ({ path, argv = [], env = process.env, execArgv = [] }) => {
|
|
8
|
-
Assert.string(path)
|
|
9
|
-
const actualArgv = ['--ipc-type=node-worker', ...argv]
|
|
10
|
-
const actualEnv = {
|
|
11
|
-
...env,
|
|
12
|
-
ELECTRON_RUN_AS_NODE: '1',
|
|
13
|
-
}
|
|
14
|
-
const worker = new Worker(path, {
|
|
15
|
-
argv: actualArgv,
|
|
16
|
-
env: actualEnv,
|
|
17
|
-
execArgv,
|
|
18
|
-
})
|
|
19
|
-
const { type, event } = await GetFirstNodeWorkerEvent.getFirstNodeWorkerEvent(worker)
|
|
20
|
-
if (type === FirstNodeWorkerEventType.Exit) {
|
|
21
|
-
throw new IpcError(`Worker exited before ipc connection was established`)
|
|
22
|
-
}
|
|
23
|
-
if (type === FirstNodeWorkerEventType.Error) {
|
|
24
|
-
throw new IpcError(`Worker threw an error before ipc connection was established: ${event}`)
|
|
25
|
-
}
|
|
26
|
-
if (event !== 'ready') {
|
|
27
|
-
throw new IpcError('unexpected first message from worker')
|
|
28
|
-
}
|
|
29
|
-
return worker
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const wrap = (worker) => {
|
|
33
|
-
return {
|
|
34
|
-
worker,
|
|
35
|
-
on(event, listener) {
|
|
36
|
-
this.worker.on(event, listener)
|
|
37
|
-
},
|
|
38
|
-
send(message) {
|
|
39
|
-
this.worker.postMessage(message)
|
|
40
|
-
},
|
|
41
|
-
sendAndTransfer(message, transfer) {
|
|
42
|
-
Assert.array(transfer)
|
|
43
|
-
this.worker.postMessage(message, transfer)
|
|
44
|
-
},
|
|
45
|
-
dispose() {
|
|
46
|
-
this.worker.terminate()
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export const withResolvers = () => {
|
|
2
|
-
/**
|
|
3
|
-
* @type {any}
|
|
4
|
-
*/
|
|
5
|
-
let _resolve
|
|
6
|
-
/**
|
|
7
|
-
* @type {any}
|
|
8
|
-
*/
|
|
9
|
-
let _reject
|
|
10
|
-
const promise = new Promise((resolve, reject) => {
|
|
11
|
-
_resolve = resolve
|
|
12
|
-
_reject = reject
|
|
13
|
-
})
|
|
14
|
-
return {
|
|
15
|
-
resolve: _resolve,
|
|
16
|
-
reject: _reject,
|
|
17
|
-
promise,
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@lvce-editor/verror'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@lvce-editor/web-socket-server'
|