Posts

Showing posts with the label Asynchronous programming

Assigning result to a function from asynchronous code

One of the more common problems that comes up in multi-threading, especially when refactoring existing code, is assigning a result obtained from asynchronous code. In other words, how do you write a function that will return some value, and calculate that value in a background thread? Basically, converting the following code: function GetData(...): string; var Data: string; begin Data := LongTask(...); // assign result of a long-running task to a function Result := Data; end; To this one: function GetData(...): string; var Data: string; begin TThread.CreateAnonymousThread( procedure begin Data := LongTask(...); end).Start; // assign result of a long-running task to a function Result := Data; end; Now, the above code will compile, but it will not achieve the desired functionality. Even if we ignore its thread safety issues (the background thread writes to the Data variable and that can interfere with assigning it to the function result), the funct...

Delphi Event-based and Asynchronous Programming Webinar Replay

Image
"Embarcadero Technologies - Conversation with Dalija Prasnikar, Embarcadero MVP, on covering her new book on Delphi Event-based and Asynchronous Programming."  Book intro by Neven Prasnikar Jr. and a recording of live Q&A chat hosted by Jim McKeeth and Stephen Ball.  https://www.youtube.com/watch?v=C8clqgydTsM Making this webinar has been quite eventful    The whole experience can be best summarized with: The year is 2021. After a whole year of lockdowns and working from home, cameras have decided they have had enough of it. Mics didn't join the rebellion  Thank you all for joining live session and watching!

Delphi Event-based and Asynchronous Programming Book - Paperback Edition and Invitation to Webinar

Image
 You asked for it, and here it is!  The paperback version of the book is here! (I hope Gaia will forgive me again...) Celebrating the release of the new book, “Delphi Event-based and Asynchronous Programming,” Jim McKeeth and I will have a chat about it during a webinar featuring a Q&A where I'll be answering your questions. Let's not reinvent the wheel here... here's the intro Jim McKeeth wrote: Join Embarcadero MVP Dalija Prasnikar and Jim McKeeth for this fireside chat about Event-Based and Asynchronous Programming in Delphi. This is your chance to get answers to your questions on the topic. Register for the webinar here: https://register.gotowebinar.com/register/9060745883744641039 Learn even more from Dalija’s recently published 291-page book: “Delphi Event-based and Asynchronous Programming,” and score a 50% discount on the physical book if you purchase the ebook!  If you have already purchased the eBook version, and wish to buy the paperback, you're also elig...

Just released: Delphi Event-based and Asynchronous Programming - Complete version - 291 Pages

Image
 Delphi Event-based and Asynchronous Programming https://dalija.prasnikar.info/delphiebap/index.html Event-based programming is everywhere. Nowadays, you can hardly write any kind of application without leaning on events and messages. This simple, yet extremely powerful mechanism is also the cornerstone of asynchronous and multithreaded programming. Without events, we would not know when some task was completed. But, asynchronous and multithreaded programming consists of more than just handling multiple threads, protecting shared resources, and synchronization. It also includes designing and understanding program flow. That design aspect is often forgotten, taken for granted, and solving all the fine-grained nuances of multithreaded programming hogs the spotlight. Without understanding asynchronous flow and the bigger picture it can be hard to properly solve all the other issues, including multithreading. What used to be plain spaghetti code, now becomes temporal spaghetti. You can...

You already purchased Delphi Event-based and Asynchronous Programming Part I?

Image
Thanks to all of you who purchased the incomplete pre-release version (179 pages) of my eBook! After a minor delay, the full version is here! You can download it through the same PDF/epub/mobi links that you have received earlier from FastSpring via email. The subject line of that email message was: "Your Delphi Event-based and Asynchronous Programming - Part I Delivery Information". If you have any problems, feel free to contact me via the contact form on my site. Thanks again! Happy Holidays to you all! 

Just released eBook: Delphi Event-based and Asynchronous Programming

Image
 Delphi Event-based and Asynchronous Programming  I just had to do it... Go with the flow! It's the Black Friday / Cyber Monday "season", so I had to rush the book offer  The book was actually scheduled for release in early December, but then the Black Friday deals started popping up all over the place... pressure was building... and I finally caved in! I cut the darn thing in two, and decided to offer Part I at a discount, and will give Part II for free to all Buyers. Not really a 97% BF discount but hey... Junior is still studying, and we still have to pay the bills (Corona doesn't help, either)! So, here it is!  I hope you'll like it like you did Delphi Memory Management! https://dalija.prasnikar.info/delphiebap/index.html Event-based programming is everywhere. Nowadays, you can hardly write any kind of application without leaning on events and messages. This simple, yet extremely powerful mechanism is also the cornerstone of asynchronous and multithreaded prog...

New Book In The Press!

Image
 Delphi Event-based and Asynchronous Programming  About to be released by the end of the month, Delphi Event-based and Asynchronous Programming brings you the following in about 260 pages: Event loops Messaging systems Asynchronous programming Removing Application.ProcessMessages and moving tasks to background threads Threads in general Tasks Futures Thread safety Communicating with the GUI And more... Stay tuned  Just released eBook: Delphi Event-based and Asynchronous Programming