Skip to content

Instantly share code, notes, and snippets.

@infynyxx
Created December 20, 2012 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infynyxx/4346133 to your computer and use it in GitHub Desktop.
Save infynyxx/4346133 to your computer and use it in GitHub Desktop.
object NettyFutureBridge {
import scala.concurrent.{ Promise, Future }
import scala.util.Try
import java.util.concurrent.CancellationException
import org.jboss.netty.channel.{ Channel, ChannelFuture, ChannelFutureListener }
def apply(nettyFuture: ChannelFuture): Future[Channel] = {
val p = Promise[Channel]()
nettyFuture.addListener(new ChannelFutureListener {
def operationComplete(future: ChannelFuture): Unit = p complete Try(
if (future.isSuccess) future.getChannel
else if (future.isCancelled) throw new CancellationException
else throw future.getCause)
})
p.future
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment