Why doesn't this work?

Hello

I’m using the PublishQueueAsyncRK library to publish events. I’d like to check that all events in the queue have been published before sleeping the device (or reaching a timeout). The waitFor function seems like an obvious way of doing this.

Can anyone explain why the following code doesn’t compile?
waitFor(publishQueue.getNumEvents()==0, 10000);

I get the following error: expression preceding parentheses of apparent call must have (pointer-to-) function type

I can achieve what I want using a while loop, but I’d like to understand why the code above doesn’t work.

Thanks for your help.

1 Like

Because the first parameter of waitFor() is not of type boolean but expects a function that returns a bool.

2 Likes

Thanks ScruffR. That makes sense. Is there any simple means of rewriting that code without creating my own function that returns a bool based on the value of publishQueue.getNumEvents()?

Actually writing your own function isn’t that hard and you don’t even need a single extra line of code :wink:

waitFor([]{return !publishQueue.getNumEvents();}, 10000);

( the black magic of lambda functions :wink: )

5 Likes

Well that’s two new things I’ve learnt today… Thanks ScruffR.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.