CoroutineLiveDataKt

public final class CoroutineLiveDataKt


Summary

Public methods

static final @NonNull LiveData<@NonNull T>
<T extends Object> liveData(
    CoroutineContext context,
    long timeoutInMs,
    @BuilderInference @ExtensionFunctionType SuspendFunction1<LiveDataScope<T>, Unit> block
)

Builds a LiveData that has values yielded from the given block that executes on a LiveDataScope.

static final @RequiresApi(value = 26) @NonNull LiveData<@NonNull T>
<T extends Object> liveData(
    CoroutineContext context,
    Duration timeout,
    @BuilderInference @ExtensionFunctionType SuspendFunction1<LiveDataScope<T>, Unit> block
)

Builds a LiveData that has values yielded from the given block that executes on a LiveDataScope.

Public methods

liveData

public static final @NonNull LiveData<@NonNull T> <T extends Object> liveData(
    CoroutineContext context,
    long timeoutInMs,
    @BuilderInference @ExtensionFunctionType SuspendFunction1<LiveDataScope<T>, Unit> block
)

Builds a LiveData that has values yielded from the given block that executes on a LiveDataScope.

The block starts executing when the returned LiveData becomes active. If the LiveData becomes inactive while the block is executing, it will be cancelled after timeoutInMs milliseconds unless the LiveData becomes active again before that timeout (to gracefully handle cases like Activity rotation). Any value LiveDataScope.emited from a cancelled block will be ignored.

After a cancellation, if the LiveData becomes active again, the block will be re-executed from the beginning. If you would like to continue the operations based on where it was stopped last, you can use the LiveDataScope.latestValue function to get the last LiveDataScope.emited value.

If the