yeow-api 0.1.4 → 0.1.8
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/package.json +1 -1
- package/src/event.ts +12 -20
package/package.json
CHANGED
package/src/event.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { call } from './task.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* Event subscription with cancellation support.
|
|
5
|
-
* Sync handlers: e.cancelled = true takes effect immediately (sync task intercepted by EventBridge).
|
|
6
|
-
* Async handlers: e.cancelled is @deprecated (no effect after await).
|
|
7
|
-
*/
|
|
8
|
-
const _handlers: Record<string, Array<{ h: Function; async: boolean }>> = {};
|
|
3
|
+
const _handlers: Record<string, Array<{ h: Function }>> = {};
|
|
9
4
|
|
|
10
5
|
function _process(internalType: string, snapshot: Record<string, unknown>): Record<string, unknown> {
|
|
11
6
|
const entries = _handlers[internalType];
|
|
@@ -20,31 +15,29 @@ function _process(internalType: string, snapshot: Record<string, unknown>): Reco
|
|
|
20
15
|
for (const key of Object.keys(snapshot)) {
|
|
21
16
|
if (!key.startsWith('_')) proxy[key] = snapshot[key];
|
|
22
17
|
}
|
|
18
|
+
const localMods: Record<string, any> = {};
|
|
23
19
|
if (cancellable) {
|
|
24
20
|
Object.defineProperty(proxy, 'cancelled', {
|
|
25
|
-
get: () =>
|
|
26
|
-
set: (v: boolean) => {
|
|
21
|
+
get: () => localMods.cancelled || false,
|
|
22
|
+
set: (v: boolean) => { localMods.cancelled = v; },
|
|
27
23
|
enumerable: true,
|
|
28
24
|
});
|
|
29
25
|
}
|
|
30
26
|
entry.h(proxy);
|
|
31
|
-
|
|
27
|
+
if (cancellable && localMods.cancelled) {
|
|
28
|
+
mods.cancelled = true;
|
|
29
|
+
}
|
|
30
|
+
} catch (e: any) { console.error(`event: ${e?.message || e}`); }
|
|
32
31
|
}
|
|
33
32
|
return mods;
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
//
|
|
37
|
-
(globalThis as any)._onEvent = (
|
|
38
|
-
|
|
39
|
-
_process(eventType, msg.sn);
|
|
40
|
-
// Notify Java that event processing is done
|
|
41
|
-
if (typeof (globalThis as any)._eventComplete === 'function') {
|
|
42
|
-
(globalThis as any)._eventComplete(eventType);
|
|
43
|
-
}
|
|
35
|
+
// SYNC_CALLBACK handler — receives snapshot, returns modifications
|
|
36
|
+
(globalThis as any)._onEvent = (eventType: string, snapshot: any): any => {
|
|
37
|
+
return _process(eventType, snapshot);
|
|
44
38
|
};
|
|
45
39
|
|
|
46
40
|
export function eventOn(eventType: string, handler: (e: any) => void): () => void {
|
|
47
|
-
const async = handler.constructor.name === 'AsyncFunction';
|
|
48
41
|
if (!_handlers[eventType]) {
|
|
49
42
|
_handlers[eventType] = [];
|
|
50
43
|
call('event.subscribe', {
|
|
@@ -52,8 +45,7 @@ export function eventOn(eventType: string, handler: (e: any) => void): () => voi
|
|
|
52
45
|
eventType,
|
|
53
46
|
});
|
|
54
47
|
}
|
|
55
|
-
|
|
56
|
-
_handlers[eventType].push(entry);
|
|
48
|
+
_handlers[eventType].push({ h: handler });
|
|
57
49
|
return () => eventOff(eventType, handler);
|
|
58
50
|
}
|
|
59
51
|
|