Is there a more spread out way of writing complex ...
# coroutines
j
Is there a more spread out way of writing complex actors?
e
No yet
j
Something for you to consider its nice to have the pull rather than the push model sometimes.
e
We already have
actor { ... }
builder for pull if I correctly understand what you mean.
j
Copy code
fun acceptor() = actor<Message> {
    var ballot = -1
    var server = -1

    var acceptedBallot: Int? = null
    var acceptedValue: Any? = null

    fun handleProposal(message: Message.Propose) {
        // Did I promise to ignore this
        when {
            message.ballot < ballot -> {
                // Yea I promised to ignore this guy
                message.reply(null)
                return
            }
            message.ballot > ballot -> {
                // Yes they are, repromise to this person
                ballot = message.ballot
                message.reply(Message.Promise(
                    message.ballot,
                    acceptedBallot,
                    acceptedValue
                ))
                return
            }
            message.ballot == ballot -> {
                TODO()
            }
        }
    }

    fun handleFinalise(message: Message.Finalise) {
        // Did we promise to ignore this
        when {
            message.ballot < ballot -> {
                // Yea we are well past this
                message.reply(null)
            }
            message.ballot >= ballot -> {
                acceptedBallot = message.ballot
                acceptedValue = message.value
                message.reply(Message.Commit(
                    message.ballot,
                    message.value
                ))
            }
            else -> TODO("pid compare.")
        }
    }

    for (it in channel) {
        when(it) {
            is Message.Propose -> handleProposal(it)
            is Message.Finalise -> handleFinalise(it)
        }
    }
}
Is what I am currently having to do