com.twitter.concurrent

Spool

sealed trait Spool[+A] extends AnyRef

A spool is an asynchronous stream. It more or less mimics the scala {{Stream}} collection, but with cons cells that have deferred tails.

Construction is done with Spool.cons, Spool.empty. Convenience syntax like that of scala.Stream is provided. In order to use these operators for deconstruction, they must be imported explicitly ({{import Spool.{*::, **:: }}} )

def fill(rest: Promise[Spool[Int]]) {
  asyncProcess foreach { result =>
    if (result.last) {
      rest() = Return(result **:: Spool.empty)
    } else {
      val next = new Promise[Spool[Int]]
      rest() = Return(result *:: next)
      fill(next)
    }
  }
}
val rest = new Promise[Spool[Int]]
fill(rest)
firstElem *:: rest

explicitly ({{import Spool.{*::, **:: }}}

def fill(rest: Promise[Spool[Int]]) {
  asyncProcess foreach { result =>
    if (result.last) {
      rest() = Return(result **:: Spool.empty)
    } else {
      val next = new Promise[Spool[Int]]
      rest() = Return(result *:: next)
      fill(next)
    }
  }
}
val rest = new Promise[Spool[Int]]
fill(rest)
firstElem *:: rest
Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Spool
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def collect[B](f: PartialFunction[A, B]): Future[Spool[B]]

    The standard Scala collect, in order to implement map & filter.

    The standard Scala collect, in order to implement map & filter.

    It may seem unnatural to return a Future[…] here, but we cannot know whether the first element exists until we have applied its filter.

  2. abstract def head: A

    The first element of the spool.

    The first element of the spool. Invalid for empty spools.

  3. abstract def isEmpty: Boolean

  4. abstract def tail: Future[Spool[A]]

    The (deferred) tail of the spool.

    The (deferred) tail of the spool. Invalid for empty spools.

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def ++[B >: A](that: Future[Spool[B]]): Future[Spool[B]]

    Concatenates two spools.

  5. def ++[B >: A](that: Spool[B]): Spool[B]

    Concatenates two spools.

  6. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  10. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  12. def filter(f: (A) ⇒ Boolean): Future[Spool[A]]

  13. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  14. def flatMap[B](f: (A) ⇒ Future[Spool[B]]): Future[Spool[B]]

    Applies a function that generates a spool to each element in this spool, flattening the result into a single spool.

  15. def foldLeft[B](z: B)(f: (B, A) ⇒ B): Future[B]

  16. def foreach[B](f: (A) ⇒ B): Future[Unit]

    Apply {{f}} for each item in the spool, until the end.

    Apply {{f}} for each item in the spool, until the end. {{f}} is applied as the items become available.

  17. def foreachElem[B](f: (Option[A]) ⇒ B): Future[Unit]

    A version of {{foreach}} that wraps each element in an {{Option}}, terminating the stream (EOF) with {{None}}.

  18. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  19. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  20. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  21. def map[B](f: (A) ⇒ B): Spool[B]

  22. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  23. final def notify(): Unit

    Definition Classes
    AnyRef
  24. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  25. def reduceLeft[B >: A](f: (B, A) ⇒ B): Future[B]

  26. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  27. def toSeq: Future[Seq[A]]

    Fully buffer the spool to a {{Seq}}.

    Fully buffer the spool to a {{Seq}}. The returned future is satisfied when the entire result is ready.

  28. def toString(): String

    Definition Classes
    AnyRef → Any
  29. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  30. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  31. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from AnyRef

Inherited from Any

Ungrouped