-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asynchronous select #416
Comments
Overall I see issues: What makes a good user API depends greatly on the usage context. It's not clear to me that one of the 3 choices (original blocking iteration, async callbacks, and event waiting) is always better than the other. So -- eventually -- I'd like to see all three styles supported. However, initially I would only support blocking iteration and async callbacks. Waiting on event handles (the second code example) really shines when there are a number of different events that corto exposes for a user app. Until then, it is unnecessarily complicated. So wait to implement this call until there are more events. Now the more complicated bit is designing a replicator API that can easily support all 3 styles. |
The unifying element in the three approaches is the iterator. A replicator interface that can provide a In addition to I would like to consider unifying the The
Instances of a class that implement this interface can be registered with observers, which will then forward all notifications to the post method in the form of an Perhaps a dispatcher could be part of a handle that is provided to |
This seems a lot like the So your thinking if a replicator implements both iteration and observation, then a dispatcher can be used to glue that to the user code with any blocking/async behaviour the user wants? PS. I've copied out the interface definitions form MS docs & .net reference source.
|
@dkantowitz Sort of. Let me clarify. This is what I'm thinking the base replicator class could look like: void notifyAction(object observable) delegate
class replicator::
// callbacks that allow pushing notifications to other stores
onDeclare, onDefine, onUpdate, onDelete: notifyAction
// selecting objects from a remote store
iterator{selectItem} select(object scope, string expr) An iterator would have the following callbacks, which can be implemented by a replicator: // Obtain next value. Should not block.
void *next();
// Iterate over a static set.
// Blocking undefined. Up to the replicator when/how it requests data from a remote source.
corto_bool hasNext();
// Will setup a push-based connection with remote store. Can block for max. timeout_ts.
// Will unblock when data is received.
// When 0 is provided as timeout, only cached data may be returned.
corto_bool waitNext(const struct timespec *timeout_ts); The select The select / wait combi would use the replicator's Dispatchers can be used for either mechanism. Instead of an asynchronous callback, a user could provide a dispatcher to a select, which will then invoke the void ThreadPool_post(corto_event e)
{
// Do something nice with the event
}
ThreadPool myDispatcher = ThreadPoolCreate(4);
corto_select(root_o, "//", myDispatcher); Similarly, the dispatcher could be used for the wait. It would be nice if each handle that can be waited for can define its own dispatcher: corto_handle h[3];
int estatus[2];
memset(&h, 0, sizeof(h));
corto_select(root_o, "a//", &h[0].iter);
corto_select(root_o, "b//", &h[1].iter);
h[0].dispatcher = myDispatcher; // Optional
while(1) {
int r = corto_wait(h, estatus, 0); // When h[0] unblocks, dispatch event
...
} |
Reworked iterators. Added onRequest callback and request method to replicators. Added logic to selectScope that sends out requests to replicators and stores the iterators.
Also switched out delegates for virtual methods.
With the new introduction of Instead, the following approach could be used, and would also allow for future additions to set more options for select:
Similarly, a regular dispatcher could be handled similarly:
|
The
corto_select
call can potentially return data from one or more replicators, which most likely will require accessing remote resources through databases, REST APIs, filesystems, messaging protocols etc. Retrieving these resources takes time and could block an application.Blocking behavior is generally undesired and thus an asynchronous alternative would be desired. Two complementary approaches have been suggested:
Through a
corto_selectAsync
call:The above approach could be extended with a
corto_selectDispatch
that uses thecorto_dispatcher
interface to dispatch events to. This would allow users to control in which thread events are handled, which for example could enable custom thread pool implementations.The other approach would involve a
poll
method in an event loop:When only a single iterator is required, the above could be simplified to:
The text was updated successfully, but these errors were encountered: