mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-02 01:08:47 +02:00
ef4c5eb65e
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
30 lines
795 B
Scala
30 lines
795 B
Scala
package com.twitter.ann.common
|
|
import com.google.common.annotations.VisibleForTesting
|
|
import com.twitter.util.{Future, FuturePool}
|
|
|
|
trait ReadWriteFuturePool {
|
|
def read[T](f: => T): Future[T]
|
|
def write[T](f: => T): Future[T]
|
|
}
|
|
|
|
object ReadWriteFuturePool {
|
|
def apply(readPool: FuturePool, writePool: FuturePool): ReadWriteFuturePool = {
|
|
new ReadWriteFuturePoolANN(readPool, writePool)
|
|
}
|
|
|
|
def apply(commonPool: FuturePool): ReadWriteFuturePool = {
|
|
new ReadWriteFuturePoolANN(commonPool, commonPool)
|
|
}
|
|
}
|
|
|
|
@VisibleForTesting
|
|
private[ann] class ReadWriteFuturePoolANN(readPool: FuturePool, writePool: FuturePool)
|
|
extends ReadWriteFuturePool {
|
|
def read[T](f: => T): Future[T] = {
|
|
readPool.apply(f)
|
|
}
|
|
def write[T](f: => T): Future[T] = {
|
|
writePool.apply(f)
|
|
}
|
|
}
|