close - Close pollable data queue - MATLAB (original) (raw)
Main Content
Close pollable data queue
Since R2025a
Syntax
Description
Examples
Define a function, sendMessages
, that sends messages to a pollable data queue. It sends five messages, simulating work by pausing for one second between sending each message.
function sendMessages(queue) for idx = 1:5 send(queue,sprintf("Message %d from worker",idx)); pause(1); end end
Create a PollableDataQueue
object, and use parfeval
to execute the sendMessages
function in the background. Pause briefly to allow the worker to send some messages.
queue = parallel.pool.PollableDataQueue; f = parfeval(backgroundPool,@sendMessages,0,queue); pause(2);
To stop the background from sending any more data to the queue, close
the PollableDataQueue
object.
Wait for the parfeval
computation to complete. Query the Error
property of future object f
to verify that an error occurred due to an attempt to send messages to the closed queue.
ans = 'Failed to send data because the DataQueue has been closed.'
Input Arguments
Pollable data queue, specified as a PollableDataQueue
object.
After you close a PollableDataQueue
object, you can no longer send data to the queue. Any attempt to send data to the queue results in an error. You can continue to poll the queue for data. You cannot reopen a closed queue.
Example: p = parallel.pool.PollableDataQueue;
Extended Capabilities
Version History
Introduced in R2025a