Define a function to call when new data is received on a DataQueue
listener = afterEach(queue, funtocall)
specifies a function
listener = afterEach(
funtocall to execute each time the
queue receives new data. You can specify multiple different
functions to call, because each call to
afterEach creates a new
listener on the queue. If you want to specify another function, call
afterEach again. To remove the registration of the function
queue, delete the returned
You must call
afterEach in the same process where you created
the data queue, otherwise an error occurs. After calling
afterEach, any current data in the queue is dispatched
immediately to the supplied function.
afterEachto Dispatch Data on a Queue
If you call
afterEach and there are items
on the queue waiting to be dispatched, these items are immediately dispatched to
afterEach function. Call
before sending data to the queue, to ensure that on
function handle specified by
afterEach is called.
DataQueue and call
q = parallel.pool.DataQueue; afterEach(q, @disp);
parfor i = 1 send(q, 2); end
You can also first send various messages to the queue. When you call
afterEach, the pending messages are passed to the
afterEach function, in this example to the function
q = parallel.pool.DataQueue; parfor i = 1 send(q, 2); end send(q, 3) afterEach(q, @disp);
DataQueue and create a listener.
D = parallel.pool.DataQueue; listener = D.afterEach(@disp);
Send some data with the value 1.
Delete the listener.
No data is returned because you have removed the callback by deleting the listener.
queue— Data queue
Data queue, specified as a
q = parallel.pool.DataQueue;
funtocall— Function handle
Function handle, specifying the function added to the list of functions to
call when a piece of new data is received from
listener = afterEach(queue,
All callback functions must accept
data as single argument.
afterEach(queue, @foo) expects a function handle
@foo to a function of the
function foo(data) end
send(queue, someData)is called on the worker,
someDatais serialized and sent back to the client.
someDatais deserialized on the client and passed as the input to