Notes /
WhatToDoAboutOutOfOrderCallbacksAn accessor that responds to input stimulus and issues an asynchronous request for a service, like an HTTP service, may receive a stream of such stimuli and issue several concurrent requests. The responses to the requests may not come back in the same order they were requested, so any outputs produced by the accessor could be out of order w.r.t. to the inputs. The current implementation of the StockTick accessor exhibits this (unfortunate) behavior. Possible solutions:
The fourth option has the advantage of codifying the pattern (put out of order responses in order) in a separate accessor that could be reused for any stream that includes a sequence number. It does make a data type assumption: the sequence number needs to be included in the output in some standardized way. Message delivery semanticsMarjan Sirjani pointed out that the ordering problem bears a strong relationship to message delivery semantics in actor models. See
Long Le has also pointed of this Node package: It offers multiple design patterns for asynchronous operations, and the main idea is using a dummy 'finish' callback that must be called after each iterator. More on Erlang messages:Messages between Erlang processes are simply valid Erlang terms. I.e. they can be lists, tuples, integers, atoms, pids etc. Each process has its own input queue for messages it receives. New messages received are put at the end of the queue. When a process executes a receive, the first message in the queue is matched against the first pattern in the receive, if this matches, the message is removed from the queue and the actions corresponding to the pattern are executed. However, if the first pattern does not match, the second pattern is tested, if this matches the message is removed from the queue and the actions corresponding to the second pattern are executed. If the second pattern does not match the third is tried and so on until there are no more pattern to test. If there are no more patterns to test, the first message is kept in the queue and we try the second message instead. If this matches any pattern, the appropriate actions are executed and the second message is removed from the queue (keeping the first message and any other messages in the queue). If the second message does not match we try the third message and so on until we reach the end of the queue. If we reach the end of the queue, the process blocks (stops execution) and waits until a new message is received and this procedure is repeated. Of course the Erlang implementation is "clever" and minimizes the number of times each message is tested against the patterns in each receive. |