nRF52832
SDK 14.2
Hi.
I would like to know how I can run a function in the background? In my case, I want to process a queue in the background. Here is the scneario:
Let's say I have two functions fooA(..) and fooB(...). If I call fooA(..), item A gets added to the queue and the function returns with QUEUED. If I call fooB(..), item B gets added to the queue and then function returns with QUEUED. (They are not executed yet.)
The queue needs to be processed to execute the items that are on the queue. My question is when and where should the processQueue function be called?
I am writing a library component and the users only have access to fooA(..) and fooB(..). The user will call these functions and they will return with QUEUED i.e item is on the queue.
But I am not sure when and how my library should be processing the queue? Should the processing be done in the background? What should trigger the processQueue(..) function to run?
Here is a rough pseudocode that I wrote to make things a bit clearer:
fooA(...){ //add item A to the queue //return QUEUED; } fooB(...){ //add item B to the queue //return QUEUED; } processQueue(..){ item = getQueueItem(..) switch(item){ case A: execute_A(..) break; case B: execute_B(..) break; } } execute_A(..){ //actual execution of A } execute_B(..){ //actual execution of B }