Today I studied the implementation of something really basic, using scala -async , namely the repetition loop for a function that might fail.
First, I could not use await() in a try/catch ; well, this was expected, I think; so I converted the function to return Future[Try[T]] instead, which, of course, is redundant under normal circumstances, since Future[T] already contains some exceptions, but allowed me to call isSuccess on the return value instead of try/catch .
Then I tried to implement loop logic. nested recursive iter() out of the question (again, as expected), because await() cannot be used in nested functions. Initially, with the good old while I led to success, since I was actually experimenting with the Future[Try[Unit]] function, so I did not like the return value; however, as soon as I changed to Future[Try[Int]] and therefore started taking care of the return value, I needed to save Try[Int] , which I selected from the await() call, to not only check if isSuccess but also return its contents. However, as soon as I tried val ret = await(...) , I received an error message:
await must not be used under a by-name argument
So, my question is, given (at least) these 3 limitations, the last of which, I would say, limits, at least, apparently, the scala rendering async, which is useless for any real life code, the selected examples are like await(x) + await(y) , what are the currently known useful real-life applications of this library?
asynchronous scala concurrency future
Erik allik
source share