Skip to content

Commit

Permalink
1. Eliminates underlying client's default request timeout which
Browse files Browse the repository at this point in the history
interferes with streaming API consumption.

2. Provides a method Http#configure for altering the client
configuration.

Fixes #30
  • Loading branch information
Nathan Hamblen committed Nov 1, 2012
1 parent 1761e23 commit 3fefb2e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/src/main/scala/execution.scala
Expand Up @@ -15,13 +15,24 @@ case class Http(
promiseExecutor: juc.Executor = Defaults.promiseExecutor,
timer: Timer = Defaults.timer
) extends HttpExecutor {
import AsyncHttpClientConfig.Builder

/** Convenience method for an Executor with the given timeout */
def waiting(t: Duration) = copy(timeout=t)

/** Convenience method for an executor with a fixed thread pool of
the given size */
def threads(promiseThreadPoolSize: Int) =
copy(promiseExecutor = DaemonThreads(promiseThreadPoolSize))

/** Replaces `client` with a new instance configured using the withBuilder
function. The current client config is the builder's prototype. */
def configure(withBuilder: Builder => Builder) =
copy(client =
new AsyncHttpClient(withBuilder(
new AsyncHttpClientConfig.Builder(client.getConfig)
).build)
)
}

/** Singleton default Http executor, can be used directly or altered
Expand All @@ -41,7 +52,8 @@ private [dispatch] object Defaults {
new NettyAsyncHttpProviderConfig().addProperty(
NettyAsyncHttpProviderConfig.BOSS_EXECUTOR_SERVICE, bossExecutor
)
).build()
).setRequestTimeoutInMs(-1) // don't timeout streaming connections
.build
lazy val bossExecutor =
juc.Executors.newCachedThreadPool(DaemonThreads.factory)
lazy val promiseExecutor = DaemonThreads(256)
Expand Down

0 comments on commit 3fefb2e

Please sign in to comment.