Skip to content

Instantly share code, notes, and snippets.

@shajra
Created September 13, 2013 00:05
Show Gist options
  • Save shajra/6545410 to your computer and use it in GitHub Desktop.
Save shajra/6545410 to your computer and use it in GitHub Desktop.
Anyone got ideas for refactoring this? The nested EitherTs don't seem finished to me, although they're compact.
trait CallStrategy[C, E] {
type State[_]
def call
(desc: CallDesc[C],
state: State[C],
pool: ExecutionContextExecutorService)
: Task[E \/ Media]
def getState
(desc: CallDesc[C], prevState: Option[State[C]])
: Task[E \/ State[C]]
def nextState
(desc: CallDesc[C], error: E, prevState: State[C])
: Task[E \/ State[C]]
def callRetryOnce
(desc: CallDesc[C],
pool: ExecutionContextExecutorService)
: EitherT[Task, E, Media] =
EitherT(getState(desc, none)) >>= { s0 =>
EitherT(call(desc, s0, pool)).swap >>= { e =>
EitherT(nextState(desc, e, s0)) >>= { s1 =>
EitherT(call(desc, s1, pool))
} swap
} swap
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment