MCPcopy
hub / github.com/square/retrofit / enqueue

Method enqueue

retrofit/src/main/java/retrofit2/OkHttpCall.java:118–185  ·  view source on GitHub ↗
(final Callback<T> callback)

Source from the content-addressed store, hash-verified

116 }
117
118 @Override
119 public void enqueue(final Callback<T> callback) {
120 Objects.requireNonNull(callback, "callback == null");
121
122 okhttp3.Call call;
123 Throwable failure;
124
125 synchronized (this) {
126 if (executed) throw new IllegalStateException("Already executed.");
127 executed = true;
128
129 call = rawCall;
130 failure = creationFailure;
131 if (call == null && failure == null) {
132 try {
133 call = rawCall = createRawCall();
134 } catch (Throwable t) {
135 throwIfFatal(t);
136 failure = creationFailure = t;
137 }
138 }
139 }
140
141 if (failure != null) {
142 callback.onFailure(this, failure);
143 return;
144 }
145
146 if (canceled) {
147 call.cancel();
148 }
149
150 call.enqueue(
151 new okhttp3.Callback() {
152 @Override
153 public void onResponse(okhttp3.Call call, okhttp3.Response rawResponse) {
154 Response<T> response;
155 try {
156 response = parseResponse(rawResponse);
157 } catch (Throwable e) {
158 throwIfFatal(e);
159 callFailure(e);
160 return;
161 }
162
163 try {
164 callback.onResponse(OkHttpCall.this, response);
165 } catch (Throwable t) {
166 throwIfFatal(t);
167 t.printStackTrace(); // TODO this is not great
168 }
169 }
170
171 @Override
172 public void onFailure(okhttp3.Call call, IOException e) {
173 callFailure(e);
174 }
175

Callers

nothing calls this directly

Calls 5

createRawCallMethod · 0.95
throwIfFatalMethod · 0.80
onFailureMethod · 0.65
cancelMethod · 0.65
enqueueMethod · 0.65

Tested by

no test coverage detected