Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise type parameter should be covariant #7467

Closed
scabug opened this issue May 9, 2013 · 2 comments
Closed

Promise type parameter should be covariant #7467

scabug opened this issue May 9, 2013 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented May 9, 2013

The type paramater on futures is covariant, promises are invariant (scala.concurrent.Promise).

I find myself having to do something similar a lot:

case class TheValue[+T](func: () => Future[T]) {
val promise = PromiseAny
val future = promise.future.asInstanceOf[Future[T]]

def process: Unit = try {
    promise.completeWith(func())
} catch {
    case x: Throwable =>
        promise.failure(x)
}

}

There might be a good way a

@scabug
Copy link
Author

scabug commented May 9, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7467?orig=1
Reporter: Colin Godsey (cgodsey)
Affected Versions: 2.10.1

@scabug
Copy link
Author

scabug commented May 9, 2013

@paulp said:
You can't make Promise covariant. You could almost make it CONTRAvariant. Please discuss this on a mailing list somewhere, we do not have the bandwidth to handle this sort of thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants