Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/julianalonso/usecase
Use case base class to use .then and .catch
https://github.com/julianalonso/usecase
catch ios operationqueue then usecase
Last synced: 16 days ago
JSON representation
Use case base class to use .then and .catch
- Host: GitHub
- URL: https://github.com/julianalonso/usecase
- Owner: JulianAlonso
- License: other
- Created: 2017-02-13T16:43:43.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-23T11:14:22.000Z (over 6 years ago)
- Last Synced: 2024-12-10T20:39:54.811Z (about 1 month ago)
- Topics: catch, ios, operationqueue, then, usecase
- Language: Swift
- Size: 21.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
UseCase
=======Use case library.
Use case base class to use `.common` `.then` and `.catch` after execute.
Any use case subclass must be initialized with a **OperationQueue**.
This class executes the code under an **Operation**, this means that UseCase can be suspended, or cancelled.## How use it.
Create a class or struct for the request and the response.Then create a subclass of UseCase with yours UseCaseRequest and UseCaseResponse.
Override the main method, this receives a operation object. When your code finish, set operation.response or operation.error to end the execution of your code.## Example:
```swift
struct TestRequest {
}
struct TestResponse {
}
enum TestError: Error {
case noRequest
}final class TestUseCase: UseCase {
override func main(request: TestRequest?, _ operation: UseCaseOperation) {
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + .milliseconds(600)) {
if request != nil {
operation.response = TestResponse()
} else {
operation.error = TestError.noRequest
}
}
}}
//Using TestUseCase:
useCase.execute()
.common {
print("Im finished.")
}
.then { response in
print("With response \(response)")
}
.catch { (error) in
print("With error \(error)")
}```
## Contributing:
If you find and issue, please, write a test that reproduce it and notify me by github issues.
If you have some idea about how to improve it, fork it, write your code, test it and send me a pull request.## Developed by:
[Julián Alonso](https://twitter.com/maisterJuli).
## LICENSE:
Apache 2.0 license. See [`LICENSE`](LICENSE) file for details