Giter Club home page Giter Club logo

tinkoffconcurrency's Introduction

TinkoffConcurrency

TL;DR

// Make URLSessionDataTask conform to TCCancellable
extension URLSessionDataTask: TCCancellable {}

func download(from url: URL) async throws -> Data {
    await withCheckedThrowingCancellableContinuation{ completion in
        let task = URLSession.shared.dataTask(with: URLRequest(url: url)) { data, _, error in
            if let data = data {
                completion(.success(data))
            } else if let error = error {
                completion(.failure(error))
            } else {
                completion(.failure(Errors.unknownError))
            }
        }

        task.resume()

        return task
    }
}
let channel = TCAsyncChannel<Int, Never>()
let filtered = channel
    .filter { $0 % 2 == 0 }

Task {
    // Available from iOS 13
    for await number in filtered.asyncValues {
        print("\(number)", terminator: " ")
    }
}

try await channel.send(1)
try await channel.send(2)
try await channel.send(3)

try channel.send(completion: .finished)

Requirements

TinkoffConcurrency requires Swift 5.5 and higher, with support of Swift Concurrency. This way, all Xcode versions starting from 13.0 would work. It's advisable to use Xcode at least 13.2.1 or higher, as it provides backward compatibility with iOS 13.0 and higher.

Installation

CocoaPods

TinkoffConcurrency is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'TinkoffConcurrency'

Swift Package Manager

  1. From File menu, select Add Packages...

  2. Enter https://github.com/tinkoff-mobile-tech/TinkoffConcurrency into repository URL

  3. Select Up to Next Major Version, and use 1.2.0 as a minimum version

  4. Select your project in Add to Project and click Add Package

  5. In opened dialog, choose target to add library to

Documentation

The documentation is available here:

Old versions

Example

To run the example project, clone the repo, and run pod install from the Example directory first. Example app is a small demo that illustrates behavior of withCheckedThrowingCancellableContinuation for both cancellable and non-cancellable tasks, and compares that to vanilla withCheckedThrowingContinuation behavior.

Example application needs iOS 15.0 to run, as it uses new SwiftUI features. It does NOT imply any restrictions of using TinkoffConcurrency library on older iOS versions.

Authors

Timur Khamidov, [email protected]

Aleksandr Darovskikh, [email protected]

License

TinkoffConcurrency is available under the Apache 2.0 license. See the LICENSE file for more info.

Attributions

Thank you Point-free for test Combine scheduler

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.