Skip to content

Commit

Permalink
feat: add isolation inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1ps committed Nov 4, 2024
1 parent 4d3a8e4 commit 2f03936
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Deadline"
BuildableName = "Deadline"
BlueprintName = "Deadline"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DeadlineTests"
BuildableName = "DeadlineTests"
BlueprintName = "DeadlineTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Deadline"
BuildableName = "Deadline"
BlueprintName = "Deadline"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
7 changes: 5 additions & 2 deletions Sources/Deadline/Deadline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ public func withDeadline<C, R>(
until instant: C.Instant,
tolerance: C.Instant.Duration? = nil,
clock: C,
isolation: isolated (any Actor)? = #isolation,
operation: @Sendable () async throws -> R
) async throws -> R where C: Clock, R: Sendable {

// NB: This is safe to use, because the closure will not escape the context of this function.
let result = await withoutActuallyEscaping(operation) { operation in
await withTaskGroup(
of: DeadlineState<R>.self,
returning: Result<R, any Error>.self
returning: Result<R, any Error>.self,
isolation: isolation
) { taskGroup in

taskGroup.addTask {
Expand Down Expand Up @@ -191,7 +193,8 @@ public func withDeadline<C, R>(
public func withDeadline<R>(
until instant: ContinuousClock.Instant,
tolerance: ContinuousClock.Instant.Duration? = nil,
isolation: isolated (any Actor)? = #isolation,
operation: @Sendable () async throws -> R
) async throws -> R where R: Sendable {
try await withDeadline(until: instant, tolerance: tolerance, clock: ContinuousClock(), operation: operation)
try await withDeadline(until: instant, tolerance: tolerance, clock: ContinuousClock(), isolation: isolation, operation: operation)
}

0 comments on commit 2f03936

Please sign in to comment.