Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

함수를 즉각 실행 시키는것이 아닌, 자기자신에게 메시지를 추가해 액터가 가진 동일한 메일함을 이용하기때문에 동시 중복실행이 일어나지 않는 특징을 가지고 있습니다.


Code Blockinfo
themeEmacs
title코드생성 프롬프트

10초에

한번씩

HelloCount를

0으로

초기화하는

이벤트를

생성하고

싶습니다.

타이머

컨셉을

적용해

모델을

개선


변경되는 코드 범위

Code Block
themeEmacs
object ResetHelloCount : HelloStateActorCommand()

/** HelloStateActor 클래스 */
class HelloStateActor private constructor(
    private val context: ActorContext<HelloStateActorCommand>,
    private val timers: TimerScheduler<HelloStateActorCommand>,
    private var state: State
) : AbstractBehavior<HelloStateActorCommand>(context) {

    companion object {
        fun create(initialState: State): Behavior<HelloStateActorCommand> {
            return Behaviors.withTimers { timers ->
                Behaviors.setup { context -> HelloStateActor(context, timers, initialState) }
            }
        }
    }

    init {
        timers.startTimerAtFixedRate(ResetHelloCount, Duration.ofSeconds(10))
    }

    private fun onResetHelloCount(command: ResetHelloCount): Behavior<HelloStateActorCommand> {
        helloCount = 0
        return this
    }

...