danielepantaleone/Resyncer
A swift library to make use of asynchronous API in a synchronous environment
Table of contents
Feature Highlights
- Compatible with iOS and macOS
- No deadlocks
- Support for callback based asynchronous code
- Support for swift-concurrency based asynchronous code
Basic usage
Resyncer enables you to call asynchronous code within a synchronous environment by pausing the current thread until the asynchronous task completes. It achieves this by offloading the asynchronous work to a separate thread, either using an OperationQueue or leveraging Swift concurrency with Task.
Because Resyncer is going to block the calling thread, make sure not to use it from the Main Thread.
Usage with callback based asynchronous code
If you have an asynchronous function that posts a value on a provided callback using swift Result (or also without Result, you can construct it yourself):
func asyncWork(_ completion: @escaping (Result<Int, Error>) -> Void) { ... }You can use Resyncer to obtain the produced value in a synchronous environment:
let x = try resyncer.synchronize { callback in
self.asyncWork { result in
callback(result)
}
}Usage with swift-concurrency based asynchronous code
If you have an asynchronous function that returns a value:
func asyncWork() async throws -> Int { ... }You can use Resyncer to obtain the produced value in a synchronous environment:
let x = try resyncer.synchronize {
try await self.asyncWork()
}Installation
Cocoapods
Add the dependency to the Resyncer framework in your Podfile:
pod 'Resyncer', '~> 1.2.0'Swift Package Manager
Add it as a dependency in a Swift Package:
dependencies: [
.package(url: "https://github.com/danielepantaleone/Resyncer.git", .upToNextMajor(from: "1.2.0"))
]Contributing
If you like this project you can contribute it by:
- Submit a bug report by opening an issue
- Submit code by opening a pull request
License
MIT License
Copyright (c) 2025 Daniele Pantaleone
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.Package Metadata
Repository: danielepantaleone/Resyncer
Stars: 7
Forks: 0
Open issues: 0
Default branch: master
Primary language: swift
License: MIT
Topics: ios, multithreading, swift, swift-concurrency, xcode
README: README.md