The promise of "Nothing" has never been completed?

I wonder why the promise of "nothing" never ends when I pass "_" as the result of completion. I came across this when I wanted to use Promise to let me know that something had ended:

val promiseWillFinish = Promise() promiseWillFinish.success(_) // will time out Await.ready(promiseWillFinish, 5 seconds) // will return false println(promiseWillFinish.isCompleted) 

Right now I'm using Promise of Unit, which works great and is also a bit more clear. But I'm still wondering which code above ends with a timeout / pending promise.

I ran this with the end of Akka 2.0.

+4
source share
2 answers

There is no possible value of type Nothing (not null , not a single one). It is impossible to promise Nothing , since a function with a result type of Nothing cannot return.

Since there is no value of type Nothing , there is no way to succeed. You are not really saying success, you are misinterpreting what is meant here:

when you declare var (and only when you declare it), you can set its default value with "_". v ar v : Int = _ set v to 0 , and var v: String = _ set it to null . If you try this with Nothing, var v : Nothing = _ , it will work. Again, there is no value of type Nothing .

On the other hand, when you write promiseWithFinish.Success(_) , this is a shortcut to

 x => promiseWithFinish.Success(x) 

You are creating a function value, not using it; you are not doing anything.

+11
source

I don't think promiseWillFinish.success(_) means what you think it means. This is a partial application, which means that the result of this expression is a function. You never called the success method, just created a new anonymous function to call the method.

I assume you had Promise[Nothing] and they tried to use _ as the default value of type Nothing . But by definition there are no values โ€‹โ€‹of type Nothing . See http://en.wikipedia.org/wiki/Bottom_type

+4
source

Source: https://habr.com/ru/post/1402847/


All Articles