![scala future scala future](https://img.edilportale.com/product-thumbs/b_prodotti-49832-relca476f65-ff87-4db4-b820-b7cb0048fc50.jpg)
Ruslan Shevchenko implemented such agent in his GitHub repository.
Scala future how to#
I’ll explain how to use this approach, though.
![scala future scala future](https://miro.medium.com/max/1400/1*DBWep0oc9Om-9DzWoasoZQ.jpeg)
The code is too long to walk through it all in this blog post. Implementing such agent is a much more complex task than creating a rather simple TracingFuture class from the previous solution. JVM allows you to register _agents_ that modify classes in runtime. If you use the agent, you can change the behavior of the Future trait’s methods like map and flatMap to do the similar thing as our compile-time solution. The second solution is to perform runtime bytecode instrumentation via JVM agent API. You can find a complete example in the demo project. It forces a programmer to use TracingFuture instead of the standard Future, though – it may be tedious to introduce this to a large codebase. This solution is nice because it mostly works at compile time and thus has close to zero performance overhead. By default, every time an Exception is instantiated it saves a current thread’s stack trace which can then be inspected when the exception is caught a.įirst, the original stack trace is printed, and then the “future trace” frames follow. Nested method invocations cause the stack to contain all method handles that are part of the invocation chain. The handle is removed from the stack (popped) when the method returns. Every time a method is invoked, its handle is pushed to the top of the stack. On the JVM, each thread has its own data area called a stack. If you feel comfortable with your knowledge about this topic jump right to the solutions. To make this article somewhat more complete I feel obliged to describe what a stack trace really is and what is so different when using Futures. Using Futures is not the only way to write asynchronous code, but this article will focus on this topic only. In this blog post I’ll cover some ways of tackling this problem when using Scala’s Futures. In asynchronous code, function invocations that form a logical chain in the source code are not confined to one thread, so stack traces are not of much help in tracing back the execution. Rules of the game have changed, however, with asynchronous programming becoming more popular. In the production environment, it often was the only way of finding the root cause of the bug.
![scala future scala future](https://media.zigcdn.com/media/content/2018/Oct/skoda-vision-rs-paris-motor-show-zigwheels-india-m5_720x540.jpg)
I suspect that most of us can relate to the process of debugging the code by burrowing through backtraces in log files.
Scala future software#
In the era of synchronous programming every software developer used to be able to use stack traces to trace function invocation chains from the place an error occurred, back to the root cause of the problem.