If you've worked with cloud APIs, you know the struggle—waiting for responses, handling event callbacks, and making sure each request happens in the right order. Things can quickly get messy, especially when multiple actions depend on each other.
To improve this, we introduced Promises in TMS FNC Core a while ago. Now, we're excited to bring Promise support directly into TMS FNC Cloud Pack! Instead of managing event handlers, Promises let you write clear, sequential code that’s easier to read and maintain.
Event-driven programming works, but it can lead to scattered logic. Take this example, where we fetch a folder list:
view plain text
Most often these 2 pieces of code will be far apart, which is harder to oversee. On top of that, the OnGetFolderList event will trigger each time GetFolderList is called, making it almost impossible to implement custom logic for separate GetFolderList calls.
With Promises, you chain operations together, keeping everything in one place:
view plain text
Now the logic is clear: Get the folder list, then update the UI—all in one place, without scattered event handlers.
When integrating Promises, we carefully evaluate where they bring the most value. One key area we identified is access token renewal. Tokens with shorter lifetimes can expire while you're working on something, causing requests to fail unexpectedly. Without Promises, handling renewals requires additional checks, event handlers, and retry logic.
To solve this, we introduced FetchAccessToken in TTMSFNCCloudOAuth. This means all descendant components automatically benefit from this improvement!
Calling FetchAccessToken returns a string with the latest valid access token. If the token is expired, it automatically retrieves a new one using the refresh token—all in a single call! Usage is as simple as:
view plain text
Or if you prefer Await:
view plain text
As a first step, we integrated promises into a selection of most-used services. These are:
Update to the latest version and take your cloud-powered applications to the next level! Have any questions, remarks or need further assistance? Feel free to reach out and don't forget to check our feature request page if you need Promises support for other cloud services.
© Copyright 2000-2023 COGITO SOFTWARE CO.,LTD. All rights reserved