MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / wrapEvent

Function wrapEvent

src/back/util/EventQueue.ts:90–110  ·  view source on GitHub ↗

* Wrap an event function in another event that resolves a promise when done. * * @param event Event function to wrap. * @returns The wrapped event function and a promise that resolves when the event is done executing, * or rejects if it rejects or throws an error. * [ wrapped

(event: EventFunction)

Source from the content-addressed store, hash-verified

88 * [ wrapped event, promise ]
89 */
90function wrapEvent(event: EventFunction): [ () => Promise<void>, Promise<void> ] {
91 // Exposed promise callbacks
92 let resolvePromise: () => void;
93 let rejectPromise: (error: any) => void;
94 // Wrap the event in another event
95 const wrappedEvent = async () => {
96 try {
97 await executeEventFunction(event);
98 resolvePromise();
99 } catch (error) {
100 rejectPromise(error);
101 }
102 };
103 // Create the promise to return (and expose its callbacks)
104 const promise = new Promise<void>((resolve, reject) => {
105 resolvePromise = resolve;
106 rejectPromise = reject;
107 });
108 // Return wrapped event and promise
109 return [wrappedEvent, promise];
110}
111
112function noop() { /* Do nothing. */ }

Callers 1

pushMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected