This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class MyAppTests: XCTestCase { | |
var cancellables: Set<AnyCancellable> = [] | |
func testDemoDataIncorrect() { | |
let start = Date.now | |
// fire an event in 1 second, but only get the first value | |
let publisher = Timer.publish(every: 1, on: .main, in: .default) | |
.autoconnect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func upload(files: [URL]) async throws -> Bool { | |
try await withThrowingTaskGroup(of: Bool.self) { group in | |
let session = try SSH(host: "xxx", port:"xxx") | |
let sftp = try session.openSftp() | |
for file in files { | |
group.addTask { | |
try await self.upload(file: file, with: sftp, session: session) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func dummyLoop() async throws { | |
print("inside dummy fcn") | |
for i in 0 ..< 10 { | |
print("Loop \(i)") | |
try await Task.sleep(for: .seconds(1)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum MyError: Error { | |
case one | |
case two | |
} | |
actor Example { | |
func funcWithTypedThrow() async throws(MyError) { throw .one } | |
// OK | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum MyError: Error { | |
case one | |
case two | |
} | |
struct MyTest { | |
private func funcWithTypedThrow() async throws(MyError) {…} | |
// example where typed-throw incorrectly concludes catch is not exhaustive | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@propertyWrapper | |
struct Synchronized<T>: @unchecked Sendable { | |
private var _wrappedValue: T | |
private let lock = NSLock() | |
var wrappedValue: T { | |
get { lock.withLock { _wrappedValue } } | |
set { lock.withLock { _wrappedValue = newValue } } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class ComplexData: @unchecked Sendable { | |
private let lock = NSLock() | |
private var _name: String | |
var name: String { | |
get { lock.withLock { _name } } | |
set { lock.withLock { _name = newValue } } | |
} | |
init(name: String) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension DispatchQueue { | |
/// Chunked concurrentPerform | |
/// | |
/// - Parameters: | |
/// | |
/// - iterations: How many total iterations. | |
/// | |
/// - chunks: How many chunks into which these iterations will be divided. This is optional and will default to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func VTT2SRT() { | |
let targetPattern = /(?<timeStamp>\d\d:\d\d:\d\d)\./ | |
var vtt = vttText.replacing(targetPattern) { $0.timeStamp + "," } | |
// … | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Task { | |
static func bar() { | |
Task<Void, Error> { | |
try await foo() | |
} | |
} | |
} | |
extension Task where Success == Void, Failure == Error { | |
static func baz() { |
NewerOlder