Changeset View
Changeset View
Standalone View
Standalone View
web/types/worker-types.js
// @flow | // @flow | ||||
// The types of messages sent from app to worker | // The types of messages sent from app to worker | ||||
export const workerRequestMessageTypes = Object.freeze({ | export const workerRequestMessageTypes = Object.freeze({ | ||||
PING: 0, | PING: 0, | ||||
}); | }); | ||||
export type PingWorkerRequestMessage = { | export type PingWorkerRequestMessage = { | ||||
+type: 0, | +type: 0, | ||||
+text: string, | +text: string, | ||||
}; | }; | ||||
export type WorkerRequestMessage = PingWorkerRequestMessage; | export type WorkerRequestMessage = PingWorkerRequestMessage; | ||||
export type WorkerRequestProxyMessage = { | |||||
+id: number, | |||||
+message: WorkerRequestMessage, | |||||
}; | |||||
// The types of messages sent from worker to app | // The types of messages sent from worker to app | ||||
export const workerResponseMessageTypes = Object.freeze({ | export const workerResponseMessageTypes = Object.freeze({ | ||||
PONG: 0, | PONG: 0, | ||||
}); | }); | ||||
export type ErrorWorkerResponseMessage = { | |||||
+error: Error, | |||||
}; | |||||
export type PongWorkerResponseMessage = { | export type PongWorkerResponseMessage = { | ||||
+type: 0, | +type: 0, | ||||
+text: string, | +text: string, | ||||
}; | }; | ||||
export type WorkerResponseMessage = | export type WorkerResponseMessage = PongWorkerResponseMessage; | ||||
| PongWorkerResponseMessage | |||||
| ErrorWorkerResponseMessage; | export type WorkerResponseProxyMessage = { | ||||
+id?: number, | |||||
+message?: WorkerResponseMessage, | |||||
+error?: Error, | |||||
}; | |||||
// SharedWorker types | // SharedWorker types | ||||
export type SharedWorkerMessageEvent = MessageEvent & { | export type SharedWorkerMessageEvent = MessageEvent & { | ||||
+ports: $ReadOnlyArray<MessagePort>, | +ports: $ReadOnlyArray<MessagePort>, | ||||
... | ... | ||||
}; | }; |