drakeet / retrofit-agera-call-adapter

Retrofit Agera Call Adapter
Apache License 2.0
114 stars 9 forks source link

java.lang.RuntimeException: Only one Looper may be created per thread #1

Closed XunMengWinter closed 8 years ago

XunMengWinter commented 8 years ago

// retrofit-agera-call-adapter-master/agera-call-adapter/src/main/java/me/drakeet/retrofit2/adapter/agera/CallResponseReservoir.java

line 45

ghost commented 8 years ago

As per the discussion here this library should never call Looper.prepare(). I believe this is needed since the library uses Reservoir<T> incorrectly and not Supplier<Result<T> as I have suggested. Using Reservoir<T> turns the values into not only a Receiver (incorrectly so, since it's not using the fact) but also into an Observable (also, incorrectly, since it's not using this either). This problem, and the problem with turning every thread that's ever used with this library into a looper thread, will go away if my suggestions are followed.

CaMnter commented 8 years ago

@ernstsson Pretty cool!

drakeet commented 8 years ago

@ernstsson Ha ha, very happy to see your help.

@XunMengWinter I am busy with my work recently, only write open source at night. But I am going to use Supplier to instead of Reservoir, wait for some time please, and I want to know: If write Supplier<Result<T>>, can you accept it?

CaMnter commented 8 years ago
    public static void prepare() {
        prepare(true);
    }
    private static void prepare(boolean quitAllowed) {
        if (sThreadLocal.get() != null) {
            throw new RuntimeException("Only one Looper may be created per thread");
        }
        sThreadLocal.set(new Looper(quitAllowed));
    }

A thread can be executed once Looper.prepare()

drakeet commented 8 years ago

It has fixed in #2

70kg commented 8 years ago

hi, @drakeet can you accept this?πŸ˜‚ Supplier<Result<Response<BoloHttpResult<IdentityList>>>> getIdentityList();

drakeet commented 8 years ago

@70kg Chinese has a word called: "η‰΅εΌΊι™„δΌš(far-fetched)". πŸ˜‚πŸŒš