From 6a871414ead65f0baf8317d69e2cbae11f6a9854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petrus=20Nguy=E1=BB=85n=20Th=C3=A1i=20H=E1=BB=8Dc?= Date: Fri, 20 May 2022 17:16:58 +0700 Subject: [PATCH] docs(defer) --- src/commonMain/kotlin/com/hoc081098/flowext/defer.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/commonMain/kotlin/com/hoc081098/flowext/defer.kt b/src/commonMain/kotlin/com/hoc081098/flowext/defer.kt index 0071124b..d5fb5ff9 100644 --- a/src/commonMain/kotlin/com/hoc081098/flowext/defer.kt +++ b/src/commonMain/kotlin/com/hoc081098/flowext/defer.kt @@ -25,7 +25,14 @@ package com.hoc081098.flowext import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.FlowCollector import kotlinx.coroutines.flow.emitAll import kotlinx.coroutines.flow.flow +/** + * Creates a [Flow] that, on collection, calls a [Flow] factory to make a [Flow] for each new [FlowCollector]. + * + * In some circumstances, waiting until the last minute (that is, until collection time) + * to generate the [Flow] can ensure that collectors receive the freshest data. + */ public fun defer(flowFactory: suspend () -> Flow): Flow = flow { emitAll(flowFactory()) }