Skip to content

Support async versions of Send and Publish #3

Closed

Description

@iancooper
No description provided.

Activity

  1. iancooper commented on Sep 30, 2014

    @iancooper
    MemberAuthor

    Creating AsyncSend or AsyncPublish, feels like applying concurrency at the wrong level; Send and Publish are not the 'work' boundary.

    Making a Request Handler async which seems more natural as the handler is the use-case or transactional boundary and would also make sense as the Task boundary. So something like Task Handle(T command) feels like a better fit. The Command Dispatcher would then wait on the Handle method, catch any exceptions and return results. That could probably be implemented as a hander, so that you could simply declare [AsyncHandler] as an attribute over changing the signature.

    The problem is that the scenario most folks are thinking about is an async ASP.NET controller action and they want to declare the method async so that it yields control on an I/O operation.

    I'm still not reconciled what I want to do about this, so no decision as yet

  2. self-assigned this
    on Dec 16, 2014
  3. iancooper commented on Jun 27, 2015

    @iancooper
    MemberAuthor

    Pondering upon this the issue that the asynchronous and synchronous pipelines are quite different. Consider that the in the Russian Doll model, if you await, then we have to consider what code will run as part of the completion (everything after the await inside the method body) and what code needs to run because we are now exiting the handler. This implies that the entire pipeline has to be async. It also means that we need to think about the default way that we call a successor now.

    So I think the first thoughts here are wrong: this is a separate pipeline approach and we do need a SendAsync, PublishAsync, and PostAsync.

    There is a some sharing - much of how we build a pipeline is similar, we just need different signatures, base objects in the async chain.

    It would have been nice to support some async handlers in the chain, but I think the nature of async I/O and the russian doll model means that we can't effect this. So I think the whole pipeline has to be async.

    The downside here, is that we won't find it easy to just call an existing pipeline using the *Async methods, you'll actually have to alter a handler to get support for async.

  4. Red-F commented on Jan 1, 2016

    @Red-F
    Contributor

    Ian, I have read the above and after some (but definitely still insufficient) thinking created an implementation of SendAsync. The IAmACommandProcessor interface has been extended with:

            /// <summary>
            /// Awaitably sends the specified command.
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="command">The command.</param>
            /// <returns>awaitable <see cref="Task"/>.</returns>
            Task SendAsync<T>(T command) where T : class, IRequest;

    My current implementation builds a separate async pipeline, but does not break any of the existing code, tests and examples.

    There is actually not much 'my' code, just (copies of) existing code with modifications.

    Added:

    • AsyncHandlerFactory.cs
    • AsyncPipelines.cs
    • AsyncRequestHandler.cs
    • AsyncRequestHandlerAttribute.cs
    • AsyncRequestHandler.cs
    • IAmAnAsyncHandlerFactory.cs
    • IHandleRequestsAsync.cs
    • a working HelloWorldAsync project

    Modified:

    • SpyCommandProcessor.cs (for tests)
    • CommandProcessor.cs
    • CommandProcessorBuilder.cs
    • HandlerConfiguration.cs
    • IAmACommandProcessor.cs
    • IAmALifetime.cs
    • Interpreter.cs
    • LifetimeScope.cs
    • PipelineBuilder.cs
    • SubscriberRegistry.cs
    • ReflectionExtensions.cs
    • and the solution and relevant projects

    Can you please create a branch named 'async' then I will issue a PR against it and we can review and discuss the approach I have taken so far.

    I have not yet created the Async equivalents of the eventsourcing, logging, monitoring and policy attributes but that is not a big deal. Also I'm still considering to support the use of 'regular' (non-async/await) handlers in the async pipeline. That shoiuld be doable. The other way around, using async handlers in a non-async pipeline, looks inadvisable.

    Regards,
    Fred Hoogduin

  5. iancooper commented on Jan 1, 2016

    @iancooper
    MemberAuthor

    I've created the async branch

  6. 56 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions