watchGameServer

abstract fun watchGameServer(): Flow<Sdk.GameServer>(source)

Subscribes to changes of the GameServer resource of this instance. The Flow receives a new item, whenever a change is made to the resource. For changes triggered by this SDK as well as for external changes applied directly to the GameServer resource within Kubernetes. The items always contain all properties of the updated GameServer resource and not just the updated fields.

The first item that is received right after registration corresponds to the current state of the resource (without any change having occurred). The Flow is triggered asynchronously and the streamed items can be inspected and processed concurrently. New states are waiting in the Flow to be fetched, so the implementation does not have to be thread-safe.

To unsubscribe from the updates, the returned Flow can be cancelled and the underlying stream will be closed and cleaned up. It can be started to subscribe again after that, by invoking this method again and obtaining a new, independent Flow.

Since the stream (if not terminated beforehand) runs indefinitely, it may delay the shutdown of the SDK, and it should be terminated beforehand. To avoid waiting for the maximum timeout, all streams should be closed beforehand. If there are still open streams, an error will be published in the Flow, and the underlying stream in gRPC will be terminated.

Return

A Flow of updated GameServer resources that returns a new element every time there was an update to the underlying data. Always contains the whole dataset and not only the modified fields.

See also

Samples


fun main() { 
   //sampleStart 
   // host and port are supplied by the default environment variables
val sdk = GrpcAgonesSdk()

// watch the game server and act on updates until a condition is met
sdk.watchGameServer()
    .takeWhile { !initialized }
    .collect { // do something } 
   //sampleEnd
}