Sometimes this server side code will use async functions to make requests to other services (e.g. external api’s).
Typically you could use a Promise or async functions but this does not work in bubble.io plugins as stated in their documentation:
If you try to use a Promise and standard async/await protocols, the bubble server side executor will not recognise to await on these functions and instead will just continue to execute the rest of the code and return immediately rather than waiting.
Instead you have to use the
context object passed into the main function to handle your async calls.
This is a working example of how this works.
context.async you can pass a function into it which bubble will run in an async manner.
In this example, the timeout will cause the bubble servers to wait 5 seconds before continuing with the script. As you can see in the console, the request took over 5 seconds and after 5 seconds it printed the message ‘return from async callback’ in the console.