vbstyle-event-models 1.0.1 → 1.0.2

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.

Potentially problematic release.


This version of vbstyle-event-models might be problematic. Click here for more details.

@@ -1,17 +1,18 @@
1
1
  import { Spinlock } from "./Spinlock";
2
+ import { EventHandler, EventArgs } from "./BasicEventModel";
2
3
 
3
4
  /**
4
5
  * A simple event scheduler that uses a queue and a spinlock.
5
6
  */
6
7
  export class QueueEventScheduler {
7
- private _eventQueue: (() => void)[] = [];
8
+ private _eventQueue: EventHandler[] = [];
8
9
  private _spinlock: Spinlock = new Spinlock();
9
10
 
10
11
  /**
11
12
  * Schedule an event action to be processed.
12
13
  * @param {() => void} eventAction - The event action to be processed.
13
14
  */
14
- public async scheduleEventAction(eventAction: () => void): Promise<void> {
15
+ public async scheduleEventAction(eventAction: EventHandler): Promise<void> {
15
16
  await this._spinlock.acquireLock();
16
17
  this._eventQueue.push(eventAction);
17
18
  this._spinlock.releaseLock();
@@ -20,14 +21,14 @@ export class QueueEventScheduler {
20
21
  /**
21
22
  * Process all events in the queue.
22
23
  */
23
- public async processEvents(): Promise<void> {
24
+ public async processEvents(sender: any, e: EventArgs): Promise<void> {
24
25
  if (this._eventQueue.length === 0) {
25
26
  return;
26
27
  }
27
28
  await this._spinlock.acquireLock();
28
29
  while (this._eventQueue.length > 0) {
29
30
  const event = this._eventQueue.shift()!;
30
- event();
31
+ event(sender, e);
31
32
  }
32
33
  this._spinlock.releaseLock();
33
34
  }
package/README.md CHANGED
@@ -1,9 +1,14 @@
1
- # VB.NET-Style Event Models (TypeScript Version)
1
+ # VB.NET-Style Event Models (TypeScript Edition)
2
2
 
3
3
  A TypeScript library providing event models, message routing, and event scheduling utilities with thread safety, inspired by VB.NET's event model.
4
4
 
5
5
  Install this package via NPM: `npm install vbstyle-event-models`
6
6
 
7
+ Minor breaking change in 1.0.2: The `QueueEventScheduler` no longer supports `() => void` but requires this type from the basic event model:
8
+ ```typescript
9
+ type EventHandler = (sender: any, e: EventArgs) => void;
10
+ ```
11
+
7
12
  ## Features
8
13
 
9
14
  - **BasicEventModel**: A simple event model for registering and invoking event handlers
@@ -72,16 +77,16 @@ import { QueueEventScheduler } from 'vbstyle-event-models';
72
77
  const scheduler = new QueueEventScheduler();
73
78
 
74
79
  // Schedule events
75
- await scheduler.scheduleEvent(() => {
80
+ await scheduler.scheduleEvent((sender, e) => {
76
81
  console.log('Event 1 executed');
77
82
  });
78
83
 
79
- await scheduler.scheduleEvent(() => {
84
+ await scheduler.scheduleEvent((sender, e) => {
80
85
  console.log('Event 2 executed');
81
86
  });
82
87
 
83
88
  // Process all events
84
- await scheduler.processEvents();
89
+ await scheduler.processEvents("", []);
85
90
 
86
91
  // Clear pending events
87
92
  await scheduler.clearEvents();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vbstyle-event-models",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A TypeScript library providing event models, message routing, and event scheduling utilities with thread safety",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",