Packages

package concurrent

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. trait AsyncSeqIterator[F[_], I, A] extends AnyRef

    Provides infinite and async computation results lazily iterating over some user defined function Unlike standard Stream[]/LazyList[] from Scala, this implementation doesn't memorise previous values.

    Provides infinite and async computation results lazily iterating over some user defined function Unlike standard Stream[]/LazyList[] from Scala, this implementation doesn't memorise previous values. Unlike Future.sequence/fold we don't know beforehand how many async actions are coming

    Async iterator implements:

    - AsyncSeqIterator#foldLeft for accumulating batching results

    - AsyncSeqIterator#map to transform batch results

    - AsyncSeqIterator#foreach to iterate with effects

    For example:

     case class MyItem( value: String, cursor: Option[Int] )
    
     def initialItem(): Future[MyItem] = Future.successful(
       MyItem( "initial", Some( 1 ) )
     )
    
     def nextItem( position: Int ): Future[MyItem] = {
       if (position < 10) {
         Future.successful(
           MyItem( "next", Some( position + 1 ) )
         )
       } else {
         Future.successful(
           MyItem( "last", None )
         )
       }
     }
    
     val iterator = AsyncSeqIterator.cons[Future,MyItem, String, Int](
       initial = initialItem(),
       toValue = _.value,
       getPos = _.cursor,
       producer = nextItem
     )
    
    iterator
        .foldLeft( List[String]() ) {
           case ( all, itemValue ) =>
             all :+ itemValue
         }
    F

    async/effect monad kind (for example, standard scala.concurrent.Future or cats.effect.IO)

    I

    iterating over item type which has a some position

    A

    extracted value type (extracted from I)

    Note

    It is not possible to implement standard Iterator[] because of the sync nature of hasNext.

  2. trait AsyncTimerSupport[F[_]] extends AnyRef

    Auxiliary interface to support delayed effects for different kind of monads

    Auxiliary interface to support delayed effects for different kind of monads

    F

    effect kind (Future, IO)

  3. trait SyncScrollerAwaiter[F[_]] extends AnyRef

    Mostly for testing purposes we provide a sync scroller, so we need this auxiliary interface to provide blocking await for synchronous streams

  4. final class UniqueLockMonitor extends AutoCloseable

    A stateful implementation of an auto-closable lock/monitor for the specified lock with an ability to unlock it preliminarily.

    A stateful implementation of an auto-closable lock/monitor for the specified lock with an ability to unlock it preliminarily. The class philosophy and namings are borrowed from C++ std::unique_lock<>.

    Usage example:

    import scala.util.Using
    import java.util.concurrent.locks.ReentrantLock
    
    class Test {
    
      private val statusLock = new ReentrantLock()
    
      def tryWithResourceExample() = {
         Using( UniqueLockMonitor.lockAndMonitor( statusLock ) ) { monitor =>
            // do something inside a lock
         }
      }
    
      def preliminaryUnlockExample() = {
         Using( UniqueLockMonitor.lockAndMonitor( statusLock ) ) { monitor =>
             // do something inside a lock
             monitor.unlock()
             // do something else outside locking and UniqueLockMonitor.close() now does nothing
         }
      }
    
    }
    Note

    this class isn't reentrant and isn't supposed to be shared across threads or used as a field. This class should be used as a stack/method local variable with try-with-resources.

Value Members

  1. object AsyncSeqIterator

    Async iterator constructors

  2. object AsyncTimerSupport
  3. object SyncScrollerAwaiter
  4. object UniqueLockMonitor

Ungrouped