Contents

ptsochantaris/semalot

πŸ‘¨ "Semalot!" πŸ‘¨β€πŸ¦± "Semalot!!" πŸ‘΄ "Semalot!!!" πŸ€¦β€β™€οΈ "It's only a counter…" πŸ‘¨πŸ‘¨β€πŸ¦±πŸ‘΄ _"Shh!!!!"_

Overview

Does what it says on the tin. It's simple and efficient, does not use any dispatch locks, and does not cause any Task queue congestion.

let maxConcurrentOperations = Semalot(tickets: 3)

try await withThrowingTaskGroup { group in
    for request in lotsOfRequests {
        await maxConcurrentOperations.takeTicket()
        group.addTask {
            let data = try await urlSession.data(for: request).0
            await doThings(with: data)
            maxConcurrentOperations.returnTicket()
        }
    }
}

License

Copyright (c) 2023 Paul Tsochantaris. Licensed under the MIT License, see LICENSE for details.

Package Metadata

Repository: ptsochantaris/semalot

Default branch: main

README: README.md