PerPlayerWorkQueue

class PerPlayerWorkQueue(scope: CoroutineScope, logger: Logger)(source)

Runs work submitted for a player one item at a time, in the order it was submitted.

Launching a coroutine per message would let a fast one overtake a slow one - a cached romaji conversion finishing ahead of an uncached one sent before it - so a player's messages could appear out of order to themselves and to their recipient. A queue per player keeps each player's messages ordered while still letting different players proceed independently.

submit must be called from one thread per player (the server's command thread), since that is what makes "the order it was submitted" well defined.

Constructors

Link copied to clipboard
constructor(scope: CoroutineScope, logger: Logger)

Functions

Link copied to clipboard
fun release(playerId: UUID)

Drops the player's queue once they can no longer send anything.

Link copied to clipboard
fun submit(playerId: UUID, work: suspend () -> Unit)

Queues work behind anything already pending for playerId, unless their queue is full.