Package 

Class RunnableProvider

  • 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 Boolean isComplete
    • Method Summary

      Modifier and Type Method Description
      Boolean getIsComplete()
      abstract E invoke() Calculate the value of this Provider.
      E getOrNull() Same as get but will return null instead of throwing an exception if the value could not be computed.
      E get() Return the value sourced from this provider, throwing an exception if the provider failed to calculate a value.
      final Unit run() The main entry point for a provider, typically called by a worker thread from BackgroundTaskService.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RunnableProvider

        RunnableProvider()
    • Method Detail

      • invoke

         abstract E invoke()

        Calculate the value of this Provider. This function will be called at-most once by run. Do not call this function directly, instead use get and getOrNull which implement the correct threading behaviour and will reuse the value if it has been previously calculated.

      • getOrNull

         E getOrNull()

        Same as get but will return null instead 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.