Skip to content

Instantly share code, notes, and snippets.

@mig35
Created March 30, 2020 09:21
Show Gist options
  • Save mig35/683de4a52b3ee0899b69b0fe2c37ec5f to your computer and use it in GitHub Desktop.
Save mig35/683de4a52b3ee0899b69b0fe2c37ec5f to your computer and use it in GitHub Desktop.
open class ConcurrentStrategyWithTag(private val tag: Any) : ConcurrentStrategy() {
override fun shouldAddToPendingActions(
pendingActionCommands: RemoveOnlyList<ActionCommand<*, *>>,
runningActionCommands: List<ActionCommand<*, *>>
): Boolean {
pendingActionCommands.removeAll { command ->
command.strategy.let { it is ConcurrentStrategyWithTag && it.tag == tag }
}
return true
}
override fun shouldExecuteAction(
pendingActionCommands: RemoveOnlyList<ActionCommand<*, *>>,
runningActionCommands: List<ActionCommand<*, *>>
): Boolean =
!runningActionCommands.any { command ->
command.strategy.let { it is ConcurrentStrategyWithTag && it.tag == tag }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment