Skip to content

Commit

Permalink
Fixed Swift 5.6+ compiler crash in TaskWorkflow
Browse files Browse the repository at this point in the history
Removing the closure to a Task and just passing in the Task to the TaskWorkflow fixes the compiler crash.
  • Loading branch information
mjohnson12 committed Jun 17, 2022
1 parent 2789389 commit 97296d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions WorkflowConcurrency/Sources/TaskWorkflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Workflow
@available(iOS 13.0, macOS 10.15, *)
extension Task: AnyWorkflowConvertible where Failure == Never {
public func asAnyWorkflow() -> AnyWorkflow<Void, Success> {
TaskWorkflow(taskProvider: { self }).asAnyWorkflow()
TaskWorkflow(task: self).asAnyWorkflow()
}
}

Expand All @@ -31,18 +31,17 @@ struct TaskWorkflow<Value>: Workflow {
public typealias State = Void
public typealias Rendering = Void

var taskProvider: () -> Task<Value, Never>
private let task: Task<Value, Never>

public init(taskProvider: @escaping () -> Task<Value, Never>) {
self.taskProvider = taskProvider
public init(task: Task<Value, Never>) {
self.task = task
}

public func render(state: State, context: RenderContext<TaskWorkflow>) -> Rendering {
let sink = context.makeSink(of: AnyWorkflowAction.self)
context.runSideEffect(key: "") { [taskProvider] lifetime in
let providedTask = taskProvider()
let task = Task {
let output = await providedTask.value
context.runSideEffect(key: "") { [task] lifetime in
let sideEffectTask = Task {
let output = await task.value
if Task.isCancelled { return }
let action = AnyWorkflowAction<TaskWorkflow>(sendingOutput: output)
DispatchQueue.main.async {
Expand All @@ -51,8 +50,8 @@ struct TaskWorkflow<Value>: Workflow {
}

lifetime.onEnded {
sideEffectTask.cancel()
task.cancel()
providedTask.cancel()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions WorkflowConcurrency/Tests/TaskTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import XCTest
class PublisherTests: XCTestCase {
func test_output() {
let host = WorkflowHost(
workflow: TaskWorkflow(taskProvider: {
workflow: TaskWorkflow(task:
Task { "hello world" }
})
)
)

let expectation = XCTestExpectation()
Expand Down

0 comments on commit 97296d0

Please sign in to comment.