org.querki.requester

RequestM

Related Docs: object RequestM | package requester

class RequestM[T] extends AnyRef

The request "monad". It's actually a bit nasty, in that it's mutable, but by and large this behaves the way you expect a monad to work. In particular, it works with for comprehensions, allowing you to compose requests much the way you normally do Futures. But since it is mutable, it should never be used outside the context of an Actor.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. RequestM
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new RequestM()

Value Members

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

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  5. def clone(): AnyRef

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

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

    Definition Classes
    AnyRef → Any
  8. def filter(p: (T) ⇒ Boolean): RequestM[T]

  9. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. def flatMap[U](handler: (T) ⇒ RequestM[U]): RequestM[U]

    The central flatMap() operation, which as in any Monad is key to composing these things together.

    The central flatMap() operation, which as in any Monad is key to composing these things together.

    flatMap() is a bit tricky. The problem we have is that we need to return a RequestM *synchronously* from flatMap, so that higher-level code can compose on it. But the *real* RequestM being returned from handler won't come into existence until some indefinite time in the future. So we need to create a new one right now, and when the real one comes into existence, link its success to that of the one we're returning here.

    The initial version of this was beautiful, elegant, and caused stack overflows if you nested flatMaps more than a couple thousand levels deep. (Which, yes, we occasionally do at Querki.) The issue comes during "unwinding" time, when the innermost RequestM finally gets set to a value. The original version had it then call resolve() on the one that contained it, which called resolve() on its parent, and so on, until we finally blew the stack.

    So instead, flatMap builds an ugly but practical linked list of RequestM's, with each one essentially pointing to the one above it. We still call resolve() at each level, but those are *not* recursive; instead, we walk up the flatMap chain *tail*-recursively, resolving each node along the way. It's a bit less elegant, but doesn't cause the JVM to have conniptions.

  11. def foreach(handler: (T) ⇒ Unit): Unit

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

    Definition Classes
    AnyRef → Any
  13. def handleSucc(handler: Function1[T, _]): Unit

  14. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  15. var higherLevel: Option[RequestM[T]]

    Build up a chain of RequestM's, from lower levels to higher, so that we can unwind results iteratively instead of through the callbacks.

    Build up a chain of RequestM's, from lower levels to higher, so that we can unwind results iteratively instead of through the callbacks.

    This is rather ugly, but necessary. The original design did the unwinding completely cleanly, with each inner RequestM propagating its result by calling resolve() on the level above it. But that turned out to cause stack overflow crashes when you got to ~2000 levels of flatMap(). So we need a mechanism that can be handled iteratively (well, tail-recursively) instead.

    Attributes
    protected
  16. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  17. def map[U](handler: (T) ⇒ U): RequestM[U]

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

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

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

    Definition Classes
    AnyRef
  21. def onComplete[U](handler: (Try[T]) ⇒ U): Unit

  22. def setHigherLevel(higher: RequestM[T]): Unit

    Attributes
    protected
  23. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  24. def toString(): String

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

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. def withFilter(p: (T) ⇒ Boolean): RequestM[T]

Inherited from AnyRef

Inherited from Any

Ungrouped