UNPKG

@lf-lang/reactor-ts

Version:

A reactor-oriented programming framework in TypeScript

67 lines 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TaggedEvent = void 0; /** * An event is caused by a timer or a scheduled action. Each event is tagged * with a time instant and may carry a value of arbitrary type. The tag will * determine the event's position with respect to other events in the event * queue. */ class TaggedEvent { trigger; tag; value; /** * Pointer to the next element of the priority set that this event might * be hooked into. */ next; /** * Construct a new tagged event. * @param trigger The trigger of this event. * @param tag The tag at which this event occurs. * @param value The value associated with this event. * */ constructor(trigger, tag, value) { this.trigger = trigger; this.tag = tag; this.value = value; } /** * Return true if this event has a smaller tag than the given event, false * otherwise. * @param node The event to compare this event's tag against. */ hasPriorityOver(node) { if (node != null) { return this.getPriority().isSmallerThan(node.getPriority()); } else { return false; } } /** * Determine whether the given event is a duplicate of this one. If so, assign the * value this event to the given one. Otherwise, return false. * @param node The event adopt the value from if it is a duplicate of this one. */ updateIfDuplicateOf(node) { if (node != null && node instanceof TaggedEvent) { if (this.trigger === node.trigger && this.tag.isSimultaneousWith(node.tag)) { node.value = this.value; // update the value return true; } } return false; } /** * Return the tag associated with this event. */ getPriority() { return this.tag; } } exports.TaggedEvent = TaggedEvent; //# sourceMappingURL=event.js.map