mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 15:21:48 +03:00
Detect and override hooks of the same kind (#6842)
This change ensures that we can have at most one hook of the same action during shutdown. Verified the change on a real project. Closes #6767.
This commit is contained in:
parent
6b7cf8e705
commit
86432b5ca5
@ -36,8 +36,9 @@ class ShutdownHookActivator[F[+_, +_]: Exec: CovariantFlatMap]
|
||||
scheduled: List[UUID] = Nil
|
||||
): Receive = {
|
||||
case RegisterShutdownHook(projectId, hook) =>
|
||||
val realHook = hook.asInstanceOf[ShutdownHook[F]]
|
||||
val updated = hooks.updated(projectId, realHook :: hooks(projectId))
|
||||
val realHook = hook.asInstanceOf[ShutdownHook[F]]
|
||||
val uniqueHooks = hooks(projectId).filter(!_.isSameKind(realHook))
|
||||
val updated = hooks.updated(projectId, realHook :: uniqueHooks)
|
||||
context.become(running(updated, scheduled))
|
||||
|
||||
case ProjectClosed(projectId) =>
|
||||
|
@ -9,4 +9,7 @@ trait ShutdownHook[F[+_, +_]] {
|
||||
*/
|
||||
def execute(): F[Nothing, Unit]
|
||||
|
||||
/** Checks if the provided `hook`` refers to the same kind of action as `this`` */
|
||||
def isSameKind(hook: ShutdownHook[F]): Boolean
|
||||
|
||||
}
|
||||
|
@ -47,4 +47,17 @@ class MoveProjectDirCmd[F[+_, +_]: CovariantFlatMap: ErrorChannel](
|
||||
)
|
||||
}
|
||||
|
||||
/** Returns the project ID to which this hook refers to */
|
||||
def getProjectId(): UUID =
|
||||
projectId
|
||||
|
||||
/** @inheritdoc */
|
||||
override def isSameKind(hook: ShutdownHook[F]): Boolean = {
|
||||
hook match {
|
||||
case cmd: MoveProjectDirCmd[_] =>
|
||||
projectId == cmd.getProjectId()
|
||||
case _ =>
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user