UNPKG

nanolith

Version:

Multi-threading in no time with seamless TypeScript support.

1 lines 616 B
import{workerData}from"worker_threads";import{ParentThread}from"../service/index.js";import{assertIsNotMainThread}from"../utilities/index.js";export const MessengerList=Object.create({use:async function(e){assertIsNotMainThread("MessengerList.use");const{messengers:s}=workerData;return s[e]?s[e]:await new Promise(((s,r)=>{const t=setTimeout(r.bind(void 0,new Error(`Timed out after waiting 10 seconds to receive a messenger named ${e}`)),1e4),a=ParentThread.onMessengerReceived((r=>{r.ID===e&&(s(r),clearTimeout(t),a())}))}))}},{list:{get:()=>(assertIsNotMainThread("MessengerList.list"),workerData.messengers)}});