-
Notifications
You must be signed in to change notification settings - Fork 5
feat(stdlib): add timer (Block T), shared timer and time replicated functions #566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #566 +/- ##
==========================================
- Coverage 70.10% 65.11% -5.00%
==========================================
Files 27 38 +11
Lines 689 943 +254
Branches 119 157 +38
==========================================
+ Hits 483 614 +131
- Misses 131 242 +111
- Partials 75 87 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c58689f
to
a53b7f0
Compare
collektive-stdlib/src/commonMain/kotlin/it/unibo/collektive/stdlib/SharedTimer.kt
Fixed
Show fixed
Hide fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces timer-based functionality to the Collektive standard library, including Block T (timer), shared timer mechanisms, and time-replicated process management. The implementation enables time-aware aggregate programming by providing utilities for synchronized clocks, periodic process replication, and temporal decay mechanisms across distributed devices.
Key changes:
- Adds core timer primitives with configurable decay rates and bounds
- Implements shared clock synchronization across devices to prevent time drift
- Introduces time-replicated process management with automatic replica lifecycle control
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
collektive-stdlib/src/commonMain/kotlin/it/unibo/collektive/stdlib/Timer.kt |
Implements basic timer primitives with decay functions |
collektive-stdlib/src/commonMain/kotlin/it/unibo/collektive/stdlib/SharedTimer.kt |
Provides shared clock synchronization and distributed timer management |
collektive-stdlib/src/commonMain/kotlin/it/unibo/collektive/stdlib/TimeReplication.kt |
Implements time-based process replication with automatic cleanup |
collektive-stdlib/src/commonTest/kotlin/it/unibo/collektive/stdlib/test/SharedClockTest.kt |
Tests for shared clock synchronization behavior |
collektive-stdlib/src/commonTest/kotlin/it/unibo/collektive/stdlib/test/TimeReplicatedTest.kt |
Tests for time-replicated process functionality |
collektive-stdlib/build.gradle.kts |
Adds kotlinx-datetime dependency |
alchemist-incarnation-collektive/src/main/kotlin/it/unibo/alchemist/collektive/device/CollektiveDevice.kt |
Changes in-memory flag for device implementation |
* It starts from a [timeout] and decreases by [decayRate]. | ||
*/ | ||
fun <ID : Comparable<ID>> Aggregate<ID>.countDownWithDecay(timeout: Duration, decayRate: Duration): Duration = | ||
timer(timeout, ZERO) { time -> time - decayRate } |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The decay
parameter in the timer
call should be decayRate
instead of ZERO
. The current implementation will never decay the timer since it passes ZERO
as the decay value while the lambda correctly uses decayRate
. This should be: timer(timeout, decayRate) { time -> time - decayRate }
.
timer(timeout, ZERO) { time -> time - decayRate } | |
timer(timeout, decayRate) { time -> time - decayRate } |
Copilot uses AI. Check for mistakes.
@@ -0,0 +1,127 @@ | |||
/* | |||
* Copyright (c) 2025, Danilo Pianini, Nicolas Farabegoli, Elisa Tronetti, |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected copyright year from 2025 to 2024 for consistency with other files in the same commit.
* Copyright (c) 2025, Danilo Pianini, Nicolas Farabegoli, Elisa Tronetti, | |
* Copyright (c) 2024, Danilo Pianini, Nicolas Farabegoli, Elisa Tronetti, |
Copilot uses AI. Check for mistakes.
alignedOn(it.id) { | ||
process() | ||
} | ||
}.first() |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling .first()
on an empty collection will throw NoSuchElementException
if localRep
is empty (which can occur when maxReplicas
is 0 or on the first execution before any replicas are created). Add a check to handle the empty case or use .firstOrNull()
with appropriate default handling.
}.first() | |
}.firstOrNull() ?: process() |
Copilot uses AI. Check for mistakes.
No description provided.