File tree 4 files changed +19
-8
lines changed
Samples/WorkflowCombineSampleApp/WorkflowCombineSampleApp
4 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ extension DemoWorkflow {
17
17
18
18
// This publisher publishes the current date on a timer that fires every second
19
19
func run( ) -> AnyPublisher < Output , Never > {
20
- Timer . publish ( every: 1 , on: . main, in: . common)
20
+ Timer . publish ( every: 2 , on: . main, in: . common)
21
21
. autoconnect ( )
22
22
. map { Action ( publishedDate: $0) }
23
23
. eraseToAnyPublisher ( )
Original file line number Diff line number Diff line change @@ -46,13 +46,24 @@ extension DemoWorkflow {
46
46
// MARK: Rendering
47
47
48
48
extension DemoWorkflow {
49
- // TODO: Change this to your actual rendering type
50
49
typealias Rendering = DemoScreen
51
50
52
51
func render( state: DemoWorkflow . State , context: RenderContext < DemoWorkflow > ) -> Rendering {
52
+ // Combine-based worker example
53
53
DemoWorker ( )
54
54
. rendered ( in: context)
55
55
56
+ // Directly consume a Publisher
57
+ Timer . publish ( every: 2 , on: . main, in: . common)
58
+ . autoconnect ( )
59
+ . delay ( for: 1.0 , scheduler: DispatchQueue . main)
60
+ . asAnyWorkflow ( )
61
+ . onOutput { state, output in
62
+ state. date = Date ( )
63
+ return nil
64
+ }
65
+ . rendered ( in: context)
66
+
56
67
dateFormatter. dateStyle = . long
57
68
dateFormatter. timeStyle = . long
58
69
let formattedDate = dateFormatter. string ( from: state. date)
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ extension Publisher where Failure == Never {
25
25
asAnyWorkflow ( ) . mapOutput ( transform)
26
26
}
27
27
28
- func asAnyWorkflow( ) -> AnyWorkflow < Void , Output > {
28
+ public func asAnyWorkflow( ) -> AnyWorkflow < Void , Output > {
29
29
PublisherWorkflow ( publisher: self ) . asAnyWorkflow ( )
30
30
}
31
31
}
Original file line number Diff line number Diff line change @@ -21,17 +21,17 @@ import Foundation
21
21
import Workflow
22
22
23
23
struct PublisherWorkflow < WorkflowPublisher: Publisher > : Workflow where WorkflowPublisher. Failure == Never {
24
- public typealias Output = WorkflowPublisher . Output
25
- public typealias State = Void
26
- public typealias Rendering = Void
24
+ typealias Output = WorkflowPublisher . Output
25
+ typealias State = Void
26
+ typealias Rendering = Void
27
27
28
28
let publisher : WorkflowPublisher
29
29
30
- public init ( publisher: WorkflowPublisher ) {
30
+ init ( publisher: WorkflowPublisher ) {
31
31
self . publisher = publisher
32
32
}
33
33
34
- public func render( state: State , context: RenderContext < Self > ) -> Rendering {
34
+ func render( state: State , context: RenderContext < Self > ) -> Rendering {
35
35
let sink = context. makeSink ( of: AnyWorkflowAction . self)
36
36
context. runSideEffect ( key: " " ) { [ publisher] lifetime in
37
37
let cancellable = publisher
You can’t perform that action at this time.
0 commit comments