Git Product home page Git Product logo

Comments (6)

ZacSweers avatar ZacSweers commented on August 21, 2024

The workaround for now would be to use the coroutines-rxjava interop library

interface PandaApi {
  @GET("/")
  suspend fun getPandas(): ApiResult<Pandas, Nothing>
}

// Use rxSingle
rxSingle { pandaApi.getPandas() }
  .subscribe { result -> ... }

from eithernet.

simtse avatar simtse commented on August 21, 2024

Oh interesting, so right now, if we wanted to use ApiResult<T, E> we can't use RxJava right away. Our best bet for async calls for a codebase that uses Rx would be to use coroutines adapter and then interop with Rxjava in order to work with existing Rx chains?

from eithernet.

ZacSweers avatar ZacSweers commented on August 21, 2024

Yup seems so. In principle it works but in testing it seems this is a java limitation

from eithernet.

ZacSweers avatar ZacSweers commented on August 21, 2024

I have an idea for this: we could use Retrofit's @Tag annotation to receive a custom ResultHint that in turn holds a ResultType instance. We can then look for this hint and use it as an override.

@GET("/")
fun anRxEndpoint(@Tag resultHint: ResultHint): Single<ApiResult<SuccessType, FailureType>>

It's annoyingly not type-safe though, but we could maybe we could encourage something like this

@GET("/")
fun anRxEndpoint(@Tag resultHint: ResultHint = ResultHint.create<SuccessType, FailureType>()): Single<ApiResult<SuccessType, FailureType>>

So then callers don't have to implement it themselves

from eithernet.

ZacSweers avatar ZacSweers commented on August 21, 2024

Another, possibly better alternative would be to see if we can read the full generic type from metadata annotations on the class. We'd have to step out of retrofit's standard API and incur the metadata parsing cost, but we could make it opt-in maybe?

from eithernet.

ZacSweers avatar ZacSweers commented on August 21, 2024

I'm going to close this as infeasible for now

from eithernet.

Related Issues (20)

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.