Skip to content

Commit 825f8fe

Browse files
committed
Save instead of
1 parent b8b6c73 commit 825f8fe

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/core/federation.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import type {
66
FederateConfig,
77
Reaction,
88
Variable,
9-
TaggedEvent
9+
TaggedEvent,
10+
SchedulableAction
1011
} from "./internal";
1112
import {
1213
Log,
@@ -304,10 +305,15 @@ export class NetworkSender extends Reactor {
304305
* A network receiver is a reactor handling a network input.
305306
*/
306307
export class NetworkReceiver<T> extends Reactor {
307-
/*
308-
* A FederatePortAction instance of this NetworkReceiver.
308+
/**
309+
* A schedulable action of this NetworkReceiver's network input.
310+
*/
311+
private networkInputSchedAction: SchedulableAction<T> | undefined;
312+
313+
/**
314+
* The information of origin of this NetworkReceiver's network input action.
309315
*/
310-
private networkInputAction: FederatePortAction<T> | undefined;
316+
private networkInputActionOrigin: Origin | undefined;
311317

312318
/**
313319
* Register a federate port's action with the network receiver.
@@ -316,7 +322,10 @@ export class NetworkReceiver<T> extends Reactor {
316322
public registerNetworkInputAction(
317323
networkInputAction: FederatePortAction<T>
318324
): void {
319-
this.networkInputAction = networkInputAction;
325+
this.networkInputSchedAction = networkInputAction.asSchedulable(
326+
this._getKey(networkInputAction)
327+
);
328+
this.networkInputActionOrigin = networkInputAction.origin;
320329
}
321330

322331
/**
@@ -326,10 +335,8 @@ export class NetworkReceiver<T> extends Reactor {
326335
public handleMessage(value: T): void {
327336
// Schedule this federate port's action.
328337
// This message is untimed, so schedule it immediately.
329-
if (this.networkInputAction !== undefined) {
330-
this.networkInputAction
331-
.asSchedulable(this._getKey(this.networkInputAction))
332-
.schedule(0, value);
338+
if (this.networkInputSchedAction !== undefined) {
339+
this.networkInputSchedAction.schedule(0, value);
333340
}
334341
}
335342

@@ -360,17 +367,13 @@ export class NetworkReceiver<T> extends Reactor {
360367

361368
// FIXME: implement decentralized control.
362369

363-
if (this.networkInputAction !== undefined) {
364-
if (this.networkInputAction.origin === Origin.logical) {
365-
this.networkInputAction
366-
.asSchedulable(this._getKey(this.networkInputAction))
367-
.schedule(0, value, intendedTag);
368-
} else {
370+
if (this.networkInputSchedAction !== undefined) {
371+
if (this.networkInputActionOrigin === Origin.logical) {
372+
this.networkInputSchedAction.schedule(0, value, intendedTag);
373+
} else if (this.networkInputActionOrigin === Origin.physical) {
369374
// The schedule function for physical actions implements
370375
// Tr = max(r, R + A)
371-
this.networkInputAction
372-
.asSchedulable(this._getKey(this.networkInputAction))
373-
.schedule(0, value);
376+
this.networkInputSchedAction.schedule(0, value);
374377
}
375378
}
376379
}

0 commit comments

Comments
 (0)