I’d like to allow a background task to do a little setup on its task state, and then store its id into a data table. Some other code running on the client in a timer uses that id then to fetch the task state and update the GUI, but expects the task state to have certain fields.
In the docs at Anvil Docs | Communicating with Background Tasks, it shows three ways to get the id of a background task. None of those three ways would seem to allow a background task to get its own id.
I have all of my background tasks separated out and get called by other functions that are organized as ‘background task generators’, this way I can grab information about the task object before I return it to the client, or another function etc.
This way you could grab the id from the task object, store it in your data table, then return the task object to whatever called it to begin with (or send it nowhere, whatever).