Skip to content

Commit

Permalink
Documenting code
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Dumas committed Oct 11, 2024
1 parent 334447e commit 16b89c9
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.ProjectSignals.emptySignals
import fs2.concurrent.SignallingRef

/**
* Keeps track of a list of project signals based on given values
*/
final class ProjectSignals[A](
values: AtomicCell[IO, Map[ProjectRef, A]],
signals: AtomicCell[IO, Map[ProjectRef, SignallingRef[IO, Boolean]]]
) {

/**
* Return the signal for the given project
*/
def get(project: ProjectRef): IO[Option[SignallingRef[IO, Boolean]]] =
signals.get.map(_.get(project))

/**
* Push updates for values and recompute the signals for all values with the new predicate
*/
def refresh(updates: Map[ProjectRef, A], predicate: A => Boolean): IO[Unit] =
values.updateAndGet(_ ++ updates).flatMap { updatedValues =>
signals.evalUpdate { signals =>
Expand All @@ -28,6 +38,9 @@ final class ProjectSignals[A](
}.void
}

/**
* Return a snapshot of the signals for all the projects
*/
def activityMap: IO[Map[ProjectRef, Boolean]] =
signals.get.flatMap { signals =>
signals.toList.foldLeftM(Map.empty[ProjectRef, Boolean]) { case (acc, (project, signal)) =>
Expand Down

0 comments on commit 16b89c9

Please sign in to comment.