1 |
//
|
|
2 |
// RouteComposer
|
|
3 |
// ContextTaskMultiplexer.swift
|
|
4 |
// https://github.com/ekazaev/route-composer
|
|
5 |
//
|
|
6 |
// Created by Eugene Kazaev in 2018-2022.
|
|
7 |
// Distributed under the MIT license.
|
|
8 |
//
|
|
9 |
// Become a sponsor:
|
|
10 |
// https://github.com/sponsors/ekazaev
|
|
11 |
//
|
|
12 |
|
|
13 |
import Foundation
|
|
14 |
import UIKit
|
|
15 |
|
|
16 |
struct ContextTaskMultiplexer: AnyContextTask, CustomStringConvertible {
|
|
17 |
|
|
18 |
private var tasks: [AnyContextTask]
|
|
19 |
|
|
20 |
init(_ tasks: [AnyContextTask]) {
|
22x |
21 |
self.tasks = tasks
|
22x |
22 |
}
|
22x |
23 |
|
|
24 |
mutating func prepare(with context: AnyContext) throws {
|
23x |
25 |
tasks = try tasks.map {
|
44x |
26 |
var contextTask = $0
|
44x |
27 |
try contextTask.prepare(with: context)
|
44x |
28 |
return contextTask
|
44x |
29 |
}
|
44x |
30 |
}
|
23x |
31 |
|
|
32 |
func perform(on viewController: UIViewController, with context: AnyContext) throws {
|
23x |
33 |
try tasks.forEach { try $0.perform(on: viewController, with: context) }
|
44x |
34 |
}
|
23x |
35 |
|
|
36 |
var description: String {
|
1x |
37 |
String(describing: tasks)
|
1x |
38 |
}
|
1x |
39 |
|
|
40 |
}
|
|