Skip to content

Commit

Permalink
Improved name for anchor removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
devlaam committed Sep 5, 2023
1 parent 336944e commit 8c03653
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ whereas the java version needed around 48ms!
## Future
This library will be a replacement for my other projects that use Akka at the moment. But Leucine will not try to
copy all of Akka or follow its conventions. Changes in the design may still happen, at least until release 1.0 is reached.
The features I need myself are incorporated by now, so the coming months are devoted to testing and minor syntax changes.
Feature requests are welcome if motivated, and of course, bug reports. Please do not send a PR without consultation.
The features I need myself are incorporated by now and i successfully migrated a proprietary project of ~8600 lines of
code from AkkaJS to Leucine. So this project might actually be of some use. From now on, i will focus on bug squashing
(if needed), code improvement and incidental adding of features. So activity on this project may decrease because i
do not want to fix what is not broken. Feature requests are welcome if motivated, and of course, bug reports. Please
do not send a PR without consultation.


10 changes: 5 additions & 5 deletions shared/src/main/scala/s2a/leucine/actors/mixins/timing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ trait TimingAid(using context: ActorContext) extends ActorInit, ActorDefs :
* Returns if the post was accepted. */
protected def post[Sender >: This <: Accept](letter: MyLetter[Sender], delay: FiniteDuration, anchor: Object = this): Boolean = synchronized {
/* First remove a post that may be out there. */
dump(anchor)
clearTiming(anchor)
/* If we are not active, we may not accept this post. Otherwise ... */
if !activity.active then false else
/* ... schedule a new timer and add it to the anchors map. */
anchors.addOne(anchor -> context.schedule(callable(TimingAid.Event[Accept,This,Sender,MyLetter](anchor,letter)),delay))
true }

/**
* Stop a scheduled letter, after dump() it is guaranteed that no letters will arrive on this
* Stop a scheduled letter, after clearTiming() it is guaranteed that no letters will arrive on this
* anchor, even if the timer has already expired during execution of this letter. */
protected def dump(anchor: Object = this): Unit = synchronized {
protected def clearTiming(anchor: Object = this): Unit = synchronized {
/* We are going to cancel the timer and remove the event. This must be synchronized
* with the execution of the callable when the timer expires. So that we are sure that the timer
* is or cancelled of has expired and put its event on the events queue. Thus, call
Expand All @@ -130,7 +130,7 @@ trait TimingAid(using context: ActorContext) extends ActorInit, ActorDefs :
anchors.remove(anchor).map(_.cancel()).getOrElse(events.remove(_.anchor == anchor)) }

/** Stop all timers and make sure no delayed letters arrive any more */
protected def dumpAll(): Unit = eventsCancel()
protected def clearAllTiming(): Unit = eventsCancel()

/**
* Send a letter to yourself the moment an event takes place. When this happens the function
Expand All @@ -143,7 +143,7 @@ trait TimingAid(using context: ActorContext) extends ActorInit, ActorDefs :
* this anchor is cleared as well, if present. Returns if the expectation was accepted. */
protected def expect[Sender >: This <: Accept](fulfill: => Option[MyLetter[Sender]], anchor: Object = this): Boolean = synchronized {
/* First remove prior anchor use. */
dump(anchor)
clearTiming(anchor)
/* If we are not active, we may not accept this expectation. Otherwise ... */
if !activity.active then false else
/* ... schedule a new expectation and add it to the anchors map. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Listener extends SelectActor(Listener,"server"), TimingAid, FamilyRoot(),
Logger.info("Listener Termination Request")
/* Cancel the expectation for a new connection.
* BTW, this is automatic in stopDirect, for illustration only. */
dump(expectationAnchor)
clearTiming(expectationAnchor)
/* Stop the actor. */
stop(Actor.Stop.Direct)

Expand Down
4 changes: 2 additions & 2 deletions shared/src/test/scala/s2a/leucine/actors/mixins/timing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ trait TimingAidTest(using ac: ActorContext) :
case Clock.Done => stop(Actor.Stop.Finish)
case Clock.Stop =>
writeln(s"stop")
dumpAll()
clearAllTiming()
post(Clock.Done,30.millis)
case Clock.Twice(value) =>
if withDump then dump(anchor)
if withDump then clearTiming(anchor)
anchor = new Object
post(Clock.Result(value),9.millis, new Object)
post(Clock.Twice(value + 2),13.millis, new Object)
Expand Down

0 comments on commit 8c03653

Please sign in to comment.