blob: 34402977ec4b9b562b8c2c0a6caf99bbc51f0311 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
//
// Optional+DispatchQueue.swift
// MullvadVPN
//
// Created by pronebird on 01/09/2020.
// Copyright © 2020 Mullvad VPN AB. All rights reserved.
//
import Foundation
extension Optional where Wrapped == DispatchQueue {
/// Unwrap the `DispatchQueue` and perform the block on it, otherwise call the block
/// synchronously on the current queue when `Optional` is `.none`.
func performOnWrappedOrCurrentQueue(block: @escaping () -> Void) {
switch self {
case .some(let queue):
queue.async(execute: block)
case .none:
block()
}
}
}
|