Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Can an Actor Flush the Enqueuer of itself?

Solved!
Go to solution

Hi,

I am pretty new to Actor Framework and I would like to know how to delete messages within its enqueuer.

Let's say I have an Actor called 'alpha'. And 'alpha' class defines a VI called 'Run Task', of which I define a Message VI 'Send Run Task'. Its caller calls 'Send Run Task', then 'Run Task' starts running. Right before 'Run Task' ends, I want to make sure the Enqueuer is empty, if not I want to flush it. How is it possible?

Thank you.

TailOfGon
Certified LabVIEW Architect 2013
0 Kudos
Message 1 of 6
(6,557 Views)

Could you elaborate more on your use case?  What goal of your application are you trying to solve by flushing the queue? Perhaps there is another way to accomplish what you're trying to do.

Flushing the queue implies that you want to ignore any pending messages, which is something I usually don't do (I usually want to look at the messages and choose to ignore them or not on a case-by-case basis based on some logic or internal state within my actor).  The key thing for me is ensuring I don't accidentally skip a Stop message.

The framework will flush the queue for you when an actor stops.

Cheers,

Matt Pollock
National Instruments
0 Kudos
Message 2 of 6
(4,495 Views)
Solution
Accepted by topic author TailOfGon

You can't flush the message queue, for the reasons MattP mentions (you might miss Stop, among other things).  The actor needs to respond to every message it receives, though it is permissible for the response to be "do nothing."

I assume you want to flush the queue to avoid duplicate Send Run Task messages.  Why is alpha sending so many of these messages?

0 Kudos
Message 3 of 6
(4,495 Views)

Thanks Matt and niACS,

To be short, yes, I want to avoid duplicate Send Run Task messages. My Send Run Task gets called upon a button click event. A user might press the button twice in a row within a short period of time accidentally. I want to avoid it. It's like avoiding a duplicate 'submit' of  a credit card transaction on a web site. If it's not possible, that is okay. I just thought I was not learning enough to know how to do it.

I think my workaround will be to disable the button before calling 'Send Run Task' button. My 'alpha' actor is actually an controller of the UI. So it can re-enable the button after the Run Task ends by sending 'Send Enable Controls', which is an AF Message VI provided by my UI Actor.

As MattP mentioned, I should not miss Stop Core message. So it makes sense not to delete them all.

Thanks!

TailOfGon
Certified LabVIEW Architect 2013
0 Kudos
Message 4 of 6
(4,495 Views)

That's how I would handle it.  I'd probably call the return message "Task Completed" or some such, but that's a quibble.

0 Kudos
Message 5 of 6
(4,495 Views)

We explicitly do not allow modification of the queue. You handle the messages as they come in. Just create a state within your object that says "already running" and ignore the second message.

Your workaround -- of disabling the UI -- is also quite effective and is a good way to prevent duplication of signals from the UI layer.

0 Kudos
Message 6 of 6
(4,495 Views)