Skip to content

Commit 88db7f0

Browse files
authored
[refactor]: allow default runtime config to be set more than once (#385)
this changes the default runtime configuration logic so that it no longer tries to enforce that it can only be updated once during the execution of a process. in practice we may want to update this for all hosts created going forward from some point in time, based on a feature flag or something.
1 parent 1d4ba78 commit 88db7f0

File tree

3 files changed

+14
-35
lines changed

3 files changed

+14
-35
lines changed

Workflow/Sources/RuntimeConfiguration.swift

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,29 @@ public enum Runtime {
2222
@TaskLocal
2323
static var _currentConfiguration: Configuration?
2424

25-
static var _bootstrapConfiguration = BootstrappableConfiguration()
26-
27-
/// Bootstrap the workflow runtime with the given configuration.
28-
/// This can only be called once per process and must be called from the main thread.
25+
/// Update the base configuration used by the workflow runtime when creating
26+
/// new `WorkflowHost` instances.
27+
/// - Note: Updating this does not affect the existing configuration values used by
28+
/// extant `WorkflowHost` instances.
2929
///
3030
/// - Parameter configuration: The runtime configuration to use.
3131
@MainActor
32-
public static func bootstrap(
32+
public static func updateDefaultConfiguration(
3333
_ configureBlock: (inout Configuration) -> Void
3434
) {
3535
MainActor.preconditionIsolated(
36-
"The Workflow runtime must be bootstrapped from the main actor."
36+
"Must be called from the main actor."
3737
)
38-
guard !_isBootstrapped else {
39-
fatalError("The Workflow runtime can only be bootstrapped once.")
40-
}
4138

42-
var config = _bootstrapConfiguration.currentConfiguration
39+
var config = Configuration()
4340
configureBlock(&config)
44-
_bootstrapConfiguration._bootstrapConfig = config
41+
_defaultConfiguration = config
4542
}
4643

44+
private static var _defaultConfiguration = Configuration()
45+
4746
static var configuration: Configuration {
48-
_currentConfiguration ?? _bootstrapConfiguration.currentConfiguration
47+
_currentConfiguration ?? _defaultConfiguration
4948
}
5049

5150
/// Allows temporary customization of the runtime configuration during the execution of the `operation`.
@@ -67,17 +66,6 @@ public enum Runtime {
6766
operation: operation
6867
)
6968
}
70-
71-
// MARK: -
72-
73-
private static var _isBootstrapped: Bool {
74-
_bootstrapConfiguration._bootstrapConfig != nil
75-
}
76-
77-
/// The current runtime configuration that may have been set via `bootstrap()`.
78-
private static var _currentBootstrapConfiguration: Configuration {
79-
_bootstrapConfiguration.currentConfiguration
80-
}
8169
}
8270

8371
extension Runtime {
@@ -93,14 +81,4 @@ extension Runtime {
9381
/// This is expected to eventually be removed and become the default behavior.
9482
public var useSinkEventHandler: Bool = false
9583
}
96-
97-
struct BootstrappableConfiguration {
98-
var _bootstrapConfig: Configuration?
99-
let _defaultConfig: Configuration = .default
100-
101-
/// The current runtime configuration that may have been set via `Runtime.bootstrap()`.
102-
var currentConfiguration: Configuration {
103-
_bootstrapConfig ?? _defaultConfig
104-
}
105-
}
10684
}

Workflow/Tests/RuntimeConfigTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct RuntimeConfigTests {
3939
// reset global state...
4040
Runtime.resetConfig()
4141
}
42-
Runtime.bootstrap { cfg in
42+
Runtime.updateDefaultConfiguration { cfg in
4343
cfg.renderOnlyIfStateChanged = true
4444
}
4545

Workflow/Tests/TestUtilities.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ extension ApplyContext {
102102
// MARK: - Runtime.Config
103103

104104
extension Runtime {
105+
@MainActor
105106
static func resetConfig() {
106-
Runtime._bootstrapConfiguration = .init()
107+
Runtime.updateDefaultConfiguration { $0 = Configuration() }
107108
}
108109
}
109110

0 commit comments

Comments
 (0)