Skip to content

Commit d2a76d3

Browse files
committed
Added comments explainging the sendEachAsync change
1 parent 59e1516 commit d2a76d3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/java/com/google/firebase/messaging/FirebaseMessaging.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ public ApiFuture<BatchResponse> sendEachAsync(@NonNull List<Message> messages, b
217217
return sendEachOpAsync(messages, dryRun);
218218
}
219219

220+
// Returns an ApiFuture directly since this function is non-blocking. Individual child send
221+
// requests are still called async and run in background threads.
220222
private ApiFuture<BatchResponse> sendEachOpAsync(
221223
final List<Message> messages, final boolean dryRun) {
222224
final List<Message> immutableMessages = ImmutableList.copyOf(messages);
@@ -226,11 +228,17 @@ private ApiFuture<BatchResponse> sendEachOpAsync(
226228

227229
List<ApiFuture<SendResponse>> list = new ArrayList<>();
228230
for (Message message : immutableMessages) {
231+
// Make async send calls per message
229232
ApiFuture<SendResponse> messageId = sendOpForSendResponse(message, dryRun).callAsync(app);
230233
list.add(messageId);
231234
}
232235

236+
// Gather all futures and combine into a list
233237
ApiFuture<List<SendResponse>> responsesFuture = ApiFutures.allAsList(list);
238+
239+
// Chain this future to wrap the eventual responses in a BatchResponse without blocking
240+
// the main thread. This uses the current thread to execute, but since the transformation
241+
// function is non-blocking the transformation itself is also non-blocking.
234242
return ApiFutures.transform(
235243
responsesFuture,
236244
(responses) -> {

0 commit comments

Comments
 (0)