Created
December 20, 2012 15:54
-
-
Save infynyxx/4346133 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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