Slather logo

Coverage for "TaskCollector.swift" : 100.00%

(21 of 21 relevant lines covered)

RouteComposer/Classes/Assemblies/Helpers/TaskCollector.swift

1
//
2
// RouteComposer
3
// TaskCollector.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
15
struct TaskCollector: TaskProvider {
16
17
    private var interceptors: [AnyRoutingInterceptor] = []
262x
18
19
    private var contextTasks: [AnyContextTask] = []
262x
20
21
    private var postTasks: [AnyPostRoutingTask] = []
262x
22
23
    mutating func add(_ interceptor: some RoutingInterceptor) {
23x
24
        interceptors.append(RoutingInterceptorBox(interceptor))
23x
25
    }
23x
26
27
    mutating func add(_ contextTask: some ContextTask) {
117x
28
        contextTasks.append(ContextTaskBox(contextTask))
117x
29
    }
117x
30
31
    mutating func add(_ postTask: some PostRoutingTask) {
11x
32
        postTasks.append(PostRoutingTaskBox(postTask))
11x
33
    }
11x
34
35
    var interceptor: AnyRoutingInterceptor? {
275x
36
        !interceptors.isEmpty ? interceptors.count == 1 ? interceptors.first : InterceptorMultiplexer(interceptors) : nil
275x
37
    }
275x
38
39
    var contextTask: AnyContextTask? {
275x
40
        !contextTasks.isEmpty ? contextTasks.count == 1 ? contextTasks.first : ContextTaskMultiplexer(contextTasks) : nil
275x
41
    }
275x
42
43
    var postTask: AnyPostRoutingTask? {
275x
44
        !postTasks.isEmpty ? postTasks.count == 1 ? postTasks.first : PostRoutingTaskMultiplexer(postTasks) : nil
275x
45
    }
275x
46
47
}