Skip to content

Commit 0e8a4a2

Browse files
committed
[refactor]: allow default runtime config to be set more than once
1 parent 1d4ba78 commit 0e8a4a2

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

Workflow/Sources/RuntimeConfiguration.swift

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,30 @@ 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. Note, is unaffected by any customizations that may
27+
/// have occurred in earlier calls to this method.
28+
/// - Note: Updating this does not affect the existing configuration values used by
29+
/// extant `WorkflowHost` instances.
2930
///
3031
/// - Parameter configuration: The runtime configuration to use.
3132
@MainActor
32-
public static func bootstrap(
33+
public static func updateDefaultConfiguration(
3334
_ configureBlock: (inout Configuration) -> Void
3435
) {
3536
MainActor.preconditionIsolated(
36-
"The Workflow runtime must be bootstrapped from the main actor."
37+
"Must be called from the main actor."
3738
)
38-
guard !_isBootstrapped else {
39-
fatalError("The Workflow runtime can only be bootstrapped once.")
40-
}
4139

42-
var config = _bootstrapConfiguration.currentConfiguration
40+
var config = Configuration()
4341
configureBlock(&config)
44-
_bootstrapConfiguration._bootstrapConfig = config
42+
_defaultConfiguration = config
4543
}
4644

45+
private static var _defaultConfiguration = Configuration()
46+
4747
static var configuration: Configuration {
48-
_currentConfiguration ?? _bootstrapConfiguration.currentConfiguration
48+
_currentConfiguration ?? _defaultConfiguration
4949
}
5050

5151
/// Allows temporary customization of the runtime configuration during the execution of the `operation`.
@@ -67,17 +67,6 @@ public enum Runtime {
6767
operation: operation
6868
)
6969
}
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-
}
8170
}
8271

8372
extension Runtime {
@@ -93,14 +82,4 @@ extension Runtime {
9382
/// This is expected to eventually be removed and become the default behavior.
9483
public var useSinkEventHandler: Bool = false
9584
}
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-
}
10685
}

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)