blob: 9d28bb14136726d79ee8f03da33669c754c05120 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
//
// OperationBlockObserverSupport.swift
// Operations
//
// Created by Jon Petersson on 2023-09-07.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import Foundation
public protocol OperationBlockObserverSupport {}
extension OperationBlockObserverSupport where Self: AsyncOperation {
/// Add observer responding to cancellation event.
public func onCancel(_ fn: @escaping (Self) -> Void) {
addBlockObserver(OperationBlockObserver(didCancel: fn))
}
/// Add observer responding to finish event.
public func onFinish(_ fn: @escaping (Self, Error?) -> Void) {
addBlockObserver(OperationBlockObserver(didFinish: fn))
}
/// Add observer responding to start event.
public func onStart(_ fn: @escaping (Self) -> Void) {
addBlockObserver(OperationBlockObserver(didStart: fn))
}
/// Add block-based observer.
public func addBlockObserver(_ observer: OperationBlockObserver<Self>) {
addObserver(observer)
}
}
|