-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.swift
39 lines (35 loc) · 1.44 KB
/
Utils.swift
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
34
35
36
37
38
39
//
// Utils.swift
// Ble
//
// Created by AndrewNadraliev on 30.10.2022.
// Copyright © 2022 Facebook. All rights reserved.
//
import Foundation
func log(tag: String, message: String, error: Error? = nil) {
if let error = error {
NSLog("%@: %@ \n %@", tag, message, error.localizedDescription)
} else {
NSLog("%@: %@", tag, message)
}
}
func log(tag: String, error: Error) {
NSLog("%@: %@", tag, error.localizedDescription)
}
@available(iOS 13.0, *)
public extension AsyncStream {
/// Factory function that creates an AsyncStream and returns a tuple standing for its inputs and outputs.
/// It easy the usage of an AsyncStream in a imperative code context.
/// - Parameter bufferingPolicy: A `Continuation.BufferingPolicy` value to
/// set the stream's buffering behavior. By default, the stream buffers an
/// unlimited number of elements. You can also set the policy to buffer a
/// specified number of oldest or newest elements.
/// - Returns: the tuple (input, output). The input can be yielded with values, the output can be iterated over
static func pipe(
bufferingPolicy: AsyncStream<Element>.Continuation.BufferingPolicy = .unbounded
) -> (AsyncStream<Element>.Continuation, AsyncStream<Element>) {
var continuation: AsyncStream<Element>.Continuation!
let stream = AsyncStream(bufferingPolicy: bufferingPolicy) { continuation = $0 }
return (continuation, stream)
}
}