-
- All Implemented Interfaces:
-
com.bugsnag.android.internal.dag.Provider,java.lang.Runnable
public abstract class RunnableProvider<E extends Object> implements Provider<E>, Runnable
The primary implementation of Provider, usually created using the BackgroundDependencyModule.provider function. Similar conceptually to java.util.concurrent.FutureTask but with a more compact implementation. The implementation of RunnableProvider.get is special because it behaves more like Lazy.value in that getting a value that is still pending will cause it to be run on the current thread instead of waiting for it to be run "sometime in the future". This makes RunnableProviders less bug-prone when dealing with single-thread executors (such as those in BackgroundTaskService). RunnableProvider also has special handling for the main-thread, ensuring no computational work (such as IO) is done on the main thread.
-
-
Field Summary
Fields Modifier and Type Field Description private final BooleanisComplete
-
Constructor Summary
Constructors Constructor Description RunnableProvider()
-
Method Summary
Modifier and Type Method Description BooleangetIsComplete()abstract Einvoke()Calculate the value of this Provider. EgetOrNull()Same as get but will return nullinstead of throwing an exception if the value could not be computed.Eget()Return the value sourced from this provider, throwing an exception if the provider failed to calculate a value. final Unitrun()The main entry point for a provider, typically called by a worker thread from BackgroundTaskService. -
-
Method Detail
-
getIsComplete
Boolean getIsComplete()
-
getOrNull
E getOrNull()
Same as get but will return
nullinstead of throwing an exception if the value could not be computed.
-
get
E get()
Return the value sourced from this provider, throwing an exception if the provider failed to calculate a value. Anything thrown from here will have been captured when attempting to calculate the value.
-
run
final Unit run()
The main entry point for a provider, typically called by a worker thread from BackgroundTaskService. If run has already been called this will be a no-op (including a reentrant thread), as such the task state must be checked after calling this.
This should not be called, and instead get or getOrNull should be used to obtain the value produced by invoke.
-
-
-
-