File tree 6 files changed +22
-13
lines changed
Samples/WorkflowCombineSampleApp/WorkflowCombineSampleApp
6 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -17,10 +17,10 @@ extension DemoWorkflow {
17
17
typealias Output = Action
18
18
19
19
// This publisher publishes the current date on a timer that fires every second
20
- func run( ) -> AnyPublisher < DemoWorkflow . Action , Never > {
20
+ func run( ) -> AnyPublisher < Action , Never > {
21
21
Timer . publish ( every: 1 , on: . main, in: . common)
22
22
. autoconnect ( )
23
- . map { . init ( publishedDate: $0) }
23
+ . map { Action ( publishedDate: $0) }
24
24
. eraseToAnyPublisher ( )
25
25
}
26
26
Original file line number Diff line number Diff line change 21
21
import Workflow
22
22
23
23
@available ( iOS 13 . 0 , macOS 10 . 15 , * )
24
+
24
25
extension AnyPublisher : AnyWorkflowConvertible where Failure == Never {
25
26
public func asAnyWorkflow( ) -> AnyWorkflow < Void , Output > {
26
27
return PublisherWorkflow ( publisher: self ) . asAnyWorkflow ( )
27
28
}
28
29
}
29
30
30
31
@available ( iOS 13 . 0 , macOS 10 . 15 , * )
31
- struct PublisherWorkflow < Value > : Workflow {
32
- public typealias Output = Value
32
+ struct PublisherWorkflow < WorkflowPublisher : Publisher > : Workflow where WorkflowPublisher . Failure == Never {
33
+ public typealias Output = WorkflowPublisher . Output
33
34
public typealias State = Void
34
35
public typealias Rendering = Void
35
36
36
- let publisher : AnyPublisher < Output , Never >
37
+ let publisher : WorkflowPublisher
37
38
38
- public init ( publisher: AnyPublisher < Output , Never > ) {
39
+ public init ( publisher: WorkflowPublisher ) {
39
40
self . publisher = publisher
40
41
}
41
42
Original file line number Diff line number Diff line change 32
32
public protocol Worker : AnyWorkflowConvertible where Rendering == Void {
33
33
/// The type of output events returned by this worker.
34
34
associatedtype Output
35
+ associatedtype WorkerPublisher : Publisher where
36
+ WorkerPublisher. Output == Output , WorkerPublisher. Failure == Never
35
37
36
38
/// Returns a publisher to execute the work represented by this worker.
37
- func run( ) -> AnyPublisher < Output , Never >
38
-
39
+ func run( ) -> WorkerPublisher
39
40
/// Returns `true` if the other worker should be considered equivalent to `self`. Equivalence should take into
40
41
/// account whatever data is meaningful to the task. For example, a worker that loads a user account from a server
41
42
/// would not be equivalent to another worker with a different user ID.
85
86
logger. logFinished ( status: " Cancelled " )
86
87
}
87
88
)
88
- . map { AnyWorkflowAction ( sendingOutput: $0) }
89
+ . map { AnyWorkflowAction < Self > ( sendingOutput: $0) }
89
90
}
90
91
. eraseToAnyPublisher ( )
91
92
. running ( in: context, key: state. uuidString)
Original file line number Diff line number Diff line change 16
16
17
17
#if DEBUG
18
18
19
+ import Combine
19
20
import Workflow
20
21
import WorkflowTesting
21
22
import XCTest
35
36
file: StaticString = #file, line: UInt = #line
36
37
) -> RenderTester < WorkflowType > {
37
38
expectWorkflow (
38
- type: PublisherWorkflow< OutputType> . self ,
39
+ type: PublisherWorkflow< AnyPublisher < OutputType, Never> >. self ,
39
40
key: key,
40
41
producingRendering: ( ) ,
41
42
producingOutput: output,
Original file line number Diff line number Diff line change @@ -183,10 +183,13 @@ private struct TestWorkflow: Workflow {
183
183
}
184
184
185
185
private struct TestWorker : Worker {
186
+ typealias Output = String
187
+ typealias WorkerPublisher = Just < Output >
188
+
186
189
let input : String
187
190
188
- func run( ) -> AnyPublisher < String , Never > {
189
- Just ( " " ) . eraseToAnyPublisher ( )
191
+ func run( ) -> WorkerPublisher {
192
+ Just ( " " )
190
193
}
191
194
192
195
func isEquivalent( to otherWorker: TestWorker ) -> Bool {
Original file line number Diff line number Diff line change @@ -136,11 +136,14 @@ class WorkerTests: XCTestCase {
136
136
}
137
137
138
138
struct TestWorker : Worker {
139
+ typealias Output = WorkerPublisher . Output
140
+ typealias WorkerPublisher = AnyPublisher < Int , Never >
141
+
139
142
func isEquivalent( to otherWorker: TestWorker ) -> Bool {
140
143
true
141
144
}
142
145
143
- func run( ) -> AnyPublisher < Int , Never > {
146
+ func run( ) -> WorkerPublisher {
144
147
[ 1 , 2 ] . publisher
145
148
. delay ( for: . milliseconds( 1 ) , scheduler: RunLoop . main)
146
149
. eraseToAnyPublisher ( )
You can’t perform that action at this time.
0 commit comments