GithubHelp home page GithubHelp logo

julianalonso / usecase Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 22 KB

Use case base class to use .then and .catch

License: Other

Ruby 5.98% Swift 91.18% Objective-C 2.84%
usecase ios then catch operationqueue

usecase's Introduction

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<Request, Response> 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:

struct TestRequest {

}

struct TestResponse {

}

enum TestError: Error {
    case noRequest
}

final class TestUseCase: UseCase<TestRequest, TestResponse> {

    override func main(request: TestRequest?, _ operation: UseCaseOperation<TestRequest, TestResponse>) {
        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.

LICENSE:

Apache 2.0 license. See LICENSE file for details

usecase's People

Contributors

julianalonso avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.