SteamExecutor

Swift
public final class SteamExecutor: SerialExecutor, Sendable

An executor for associating actors with Steamworks

EXPERIMENTAL

This creates a single new thread to run Actor/Task code and periodically call Steamworks – either to dispatch callbacks or do Steamworks maintenance work.

A single executor thread can support multiple APIClients so you can service a gameserver and client API from the same thread.

This solves the problem of using Swift concurrency with Steamworks outside of the main thread.

Problems:

  1. The poll resolution promised by the API is dubious – probably because of the thread priorities available via NSThread getting anything below 100ms is a bit sketchy.

To Do (perhaps):

  • Change the API clients at runtime - eg. creation of a server or something
  • Figure out what on earth is wrong with Linux vs. swift-atomics (or more likely move to built-in atomics)

Topics

Lifecycle

struct APIClient

A Steam API Client to be periodically polled

Declaration
Swift
public struct APIClient: Sendable

init(apiClients: [APIClient], qos: QualityOfService, name: String)

Create a new Steamworks-focussed executor

Declaration
Swift
public init(
    apiClients: [APIClient], qos: QualityOfService = .default,
    name: String = "SteamExecutor")
Parameters
apiClients

Description of Steamworks tasks to perform on this thread.

qos

The QualityOfServiceQualityOfService for the executor’s thread.

name

A name for the executor’s thread, used in stats and debug.

init(apiClient: APIClient, qos: QualityOfService, name: String)

Create an executor to service a single Steam API client.

See init(apiClients:qos:name:).

Declaration
Swift
public convenience init(
    apiClient: APIClient, qos: QualityOfService = .default,
    name: String = "SteamExecutor")

func stop()

Stop the executor.

Blocks until the thread has finished any pending jobs. If any actors still exist associated with this then they will stop working in a bad way.

Declaration
Swift
public func stop()

Properties

var qos: QualityOfService

The QualityOfServiceQualityOfServiceused by the executor’s thread

Declaration
Swift
public let qos: QualityOfService

var name: String

The (debug) name associated with the executor’s thread and locks

Declaration
Swift
public let name: String

var thread: Thread?

The ThreadThread for the executor, or nil if it’s not running

Declaration
Swift
public private(set) var thread: Thread? { get set }

Statistics

struct Stats

Statistics about the executor and its API clients

Declaration
Swift
public struct Stats

var stats: Stats

Get a snapshot of the executor’s statistics

Declaration
Swift
public var stats: Stats { get }