Function Friday – Multi tasking with Concurrent

Introduction
Sometimes when developing a power platform canvas app we want to be able to evaluate multiple formulas at once. This is where we can multi-task with the Concurrent function can come into play.
Multi-tasking with Concurrent
Within a Canvas app, we can chain formulas together in a single property such as a user-controlled button with a semi-colon (;) operator. For example in the onSelect property of a button:
ClearCollect(colBooks, BookInformation);
ClearCollect(colAuthors, AuthorInformation);
ClearCollect(colPublishers, PublisherInformation);
ClearCollect(colCategories, CategoryInformation);
Set(gblUserEmail, User().Email);
In this example, the canvas app will collect all the records in BookInformation, AuthorInformaiton, PublisherInformation and CategoryInformation tables and then set the gblUserEmail variable to the current user’s email address.
Power Platform will run these formulas one after the other, as such the app won’t query the AuthorInformaiton table until after it has finished querying BookInformation.
Using the concurrent function will call these simultaneously, processing the information and displaying the information when the query is returned rather than once the previous query is completed.
Concurrent(
ClearCollect(colBooks, BookInformation),
ClearCollect(colAuthors, AuthorInformation),
ClearCollect(colPublishers, PublisherInformation),
ClearCollect(colCategories, CategoryInformation),
Set(gblCurrentUser, User().Email)
);
Note that instead of using a semi-colon (;) operator, we simply separate the individual formulas with a comma (,).
As Concurrent can’t predict the order in which formulas within it will start and end they shouldn’t contain dependencies. As shown below

Conclusion
By leveraging the concurrent function in Power Platform canvas apps, we can significantly boost the performance and responsiveness of our applications. This function lets us run multiple formulas simultaneously, cutting down wait times and enhancing the user experience. However, we must ensure that the formulas within the Concurrent function are independent of each other to prevent any potential issues from unpredictable execution orders. By utilising concurrent effectively, we can streamline data processing and handle tasks more efficiently than if we performed them sequentially. With this powerful tool in your arsenal, you can build faster, more responsive apps that better serve your users.
If you’d like to check out my other Friday functions you can find them here.
Leave a comment