toffor
toffor

Reputation: 1299

What is the difference between channelFlow and callbackFlow

I am trying to understand why we need callbackFlow builder, it seems almost same with channelFlow except callbackFlow is inline. What is the use case ?

Upvotes: 16

Views: 5298

Answers (1)

Dominic Fischer
Dominic Fischer

Reputation: 1849

They do exactly the same thing. One of them literally calls the other. The difference is in the intention. It is supposed to make your code more self documenting about your intentions.

Use callback flow for callbacks and channelFlow for concurrent flow emission.

EDIT: As of Version 1.3.4, callbackFlow will detect missing calls to awaitClose, making it less error prone. So they are now different.

Upvotes: 22

Related Questions