feat(act_executor): Added strategies for incoming event#4
feat(act_executor): Added strategies for incoming event#4dmitry-kuzhelko-velmie wants to merge 3 commits intovelmie:masterfrom
Conversation
fix(LiveDataAct): fix duplicate act when generic type isn't supported
| * Save and execute only one event and ignore all new events. | ||
| * After event is executed, it becomes possible to add new event. | ||
| * | ||
| * REPLACE - Only one event can be stored at the same time. Replace already added event and ignore all new events. |
There was a problem hiding this comment.
ты тут не игнорируешь ничего
| private fun startAct(act: Act) { | ||
| when { | ||
| actMap.contains(act.id) -> Timber.d("id: ${act.id} - Act duplicate") | ||
| actMap.size() == 1 -> Timber.d("Only one event can be processed at the same time") |
There was a problem hiding this comment.
это в орне не верно, у тебя может быть сколько угодно событий в map
| private fun startReplaceAct(act: Act) { | ||
| when { | ||
| actMap.contains(act.id) -> actMap.replace(act.id, act) | ||
| actMap.size() == 1 -> Timber.d("Only one event can be processed at the same time") |
There was a problem hiding this comment.
это в орне не верно, у тебя может быть сколько угодно событий в map
| } | ||
| private fun startAct(act: Act) { | ||
| when { | ||
| actMap.contains(act.id) -> Timber.d("id: ${act.id} - Act duplicate") |
| } | ||
| private fun startAct(act: Act) { | ||
| when { | ||
| actMap.contains(act.id) -> Timber.d("id: ${act.id} - Act duplicate") |
There was a problem hiding this comment.
- мне кажется что тут будет неожиданное поведение
| actDispatcher: ActDispatchers = ActDispatchers.DEFAULT | ||
| ) : ActExecutorInterface { | ||
|
|
||
| private val scope: CoroutineScope = CoroutineScope(actDispatcher.dispatcher) |
There was a problem hiding this comment.
зачем нам глобальная корутина для инструмента?
| val invokeTime = measureTimeMillis { act.actFunction() } | ||
| job = scope.launch { | ||
| delay(act.delay - invokeTime) | ||
| removeFromMap() |
There was a problem hiding this comment.
job?.cancel() не нужен, у тебя корутина закончит свое выполнение как только будет вызван removeFromMap()
| delay(act.delay - invokeTime) | ||
| removeFromMap() | ||
| throw IllegalArgumentException("Type T in LiveData<T> unregistered") | ||
| job?.cancel() |
There was a problem hiding this comment.
а вот для replace - уже будет нужен
|
|
||
| private fun startReplaceAct(act: Act) { | ||
| when { | ||
| actMap.contains(act.id) -> actMap.replace(act.id, act) |
There was a problem hiding this comment.
ты подменяешь act и на этом все. никакой логики по replace нет
| */ | ||
|
|
||
| enum class ActStrategy() { | ||
| DEFAULT, REPLACE, QUEUE |
There was a problem hiding this comment.
давай пока откажемся от QUEUE - так будет проще. потом следующей задачей его внесем
No description provided.