28 lines
937 B
Swift
28 lines
937 B
Swift
// EngineDispatch.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Foundation
|
|
|
|
/// Dispatch a throwing engine mutation to the main queue — preserving the
|
|
/// `SynthesisEngine.pendingQueue` single-producer invariant — and log on failure.
|
|
///
|
|
/// Shared by the language-side context types (`LyrebirdRoutineContext`,
|
|
/// `LyrebirdProcessContext`) whose `add` / `schedule` calls cross from a routine
|
|
/// or process thread onto the main thread. `label` names the call site in the
|
|
/// failure message only.
|
|
func lyrebirdDispatchEngineOp(
|
|
_ label: String,
|
|
_ work: @escaping @MainActor () throws -> Void
|
|
) {
|
|
DispatchQueue.main.async {
|
|
// The block runs on the main queue, so main-actor isolation holds.
|
|
MainActor.assumeIsolated {
|
|
do { try work() }
|
|
catch { print("[Lyrebird] \(label) failed: \(error)") }
|
|
}
|
|
}
|
|
}
|