Skip to content
Browse files

Allow null callback executor.

  • Loading branch information...
1 parent 99f8b5a commit fc488cc63cf4bda33f9bb63022693e2a0ebc3ba0 @JakeWharton JakeWharton committed Nov 1, 2012
Showing with 15 additions and 3 deletions.
  1. +15 −3 retrofit/src/main/java/retrofit/http/RestAdapter.java
View
18 retrofit/src/main/java/retrofit/http/RestAdapter.java
@@ -341,10 +341,16 @@ public Builder setClient(Provider<HttpClient> clientProvider) {
return this;
}
+ /**
+ * Executors used for asynchronous HTTP client downloads and callbacks.
+ *
+ * @param httpExecutor Executor on which HTTP client calls will be made.
+ * @param callbackExecutor Executor on which any {@link Callback} methods will be invoked. If this argument is
+ * {@code null} then callback methods will be run on the same thread as the HTTP client.
+ */
public Builder setExecutors(Executor httpExecutor, Executor callbackExecutor) {
- if (httpExecutor == null || callbackExecutor == null) {
- throw new IllegalArgumentException("Both httpExecutor or callbackExecutor must not be null.");
- }
+ if (httpExecutor == null) throw new NullPointerException("httpExecutor");
+ if (callbackExecutor == null) callbackExecutor = new SynchronousExecutor();
this.httpExecutor = httpExecutor;
this.callbackExecutor = callbackExecutor;
return this;
@@ -375,4 +381,10 @@ public RestAdapter build() {
return new RestAdapter(server, clientProvider, httpExecutor, callbackExecutor, headers, converter, profiler);
}
}
+
+ private static class SynchronousExecutor implements Executor {
+ @Override public void execute(Runnable runnable) {
+ runnable.run();
+ }
+ }
}

0 comments on commit fc488cc

Please sign in to comment.
Something went wrong with that request. Please try again.