Skip to content

feat(act_executor): Added strategies for incoming event#4

Open
dmitry-kuzhelko-velmie wants to merge 3 commits into
velmie:masterfrom
dmitry-kuzhelko-velmie:strategy
Open

feat(act_executor): Added strategies for incoming event#4
dmitry-kuzhelko-velmie wants to merge 3 commits into
velmie:masterfrom
dmitry-kuzhelko-velmie:strategy

Conversation

@dmitry-kuzhelko-velmie

Copy link
Copy Markdown
Contributor

No description provided.

* 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ты тут не игнорируешь ничего

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")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это в орне не верно, у тебя может быть сколько угодно событий в 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")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это в орне не верно, у тебя может быть сколько угодно событий в map

}
private fun startAct(act: Act) {
when {
actMap.contains(act.id) -> Timber.d("id: ${act.id} - Act duplicate")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

много дублирования

}
private fun startAct(act: Act) {
when {
actMap.contains(act.id) -> Timber.d("id: ${act.id} - Act duplicate")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • мне кажется что тут будет неожиданное поведение

actDispatcher: ActDispatchers = ActDispatchers.DEFAULT
) : ActExecutorInterface {

private val scope: CoroutineScope = CoroutineScope(actDispatcher.dispatcher)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем нам глобальная корутина для инструмента?

val invokeTime = measureTimeMillis { act.actFunction() }
job = scope.launch {
delay(act.delay - invokeTime)
removeFromMap()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

job?.cancel() не нужен, у тебя корутина закончит свое выполнение как только будет вызван removeFromMap()

delay(act.delay - invokeTime)
removeFromMap()
throw IllegalArgumentException("Type T in LiveData<T> unregistered")
job?.cancel()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а вот для replace - уже будет нужен


private fun startReplaceAct(act: Act) {
when {
actMap.contains(act.id) -> actMap.replace(act.id, act)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ты подменяешь act и на этом все. никакой логики по replace нет

*/

enum class ActStrategy() {
DEFAULT, REPLACE, QUEUE

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

давай пока откажемся от QUEUE - так будет проще. потом следующей задачей его внесем

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants