package play.core.server.netty
import org.jboss.netty.channel.{ Channel, ChannelFuture, ChannelFutureListener }
import play.api.libs.concurrent._
import scala.concurrent.{ Future, Promise, ExecutionContext, CanAwait }
import scala.concurrent.duration.Duration
import java.util.concurrent.TimeUnit
import scala.util._
object NettyFuture {
implicit class ToScala(channelFuture: ChannelFuture) {
def toScala: Future[Channel] = {
val promise = Promise[Channel]()
channelFuture.addListener(new ChannelFutureListener {
def operationComplete(future: ChannelFuture) = {
if (future.isSuccess) {
promise.success(future.getChannel)
} else if (future.isCancelled) {
promise.failure(new RuntimeException("Future cancelled"))
} else {
promise.failure(future.getCause)
}
}
})
promise.future
}
}
}