Skip to content

Commit

Permalink
Merge branch 'master' into unix-domain-socket
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc authored Jan 13, 2022
2 parents 2469757 + 5ee8e62 commit c6af515
Show file tree
Hide file tree
Showing 17 changed files with 1,190 additions and 733 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Cysharp, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion MessagePipe.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31410.414
VisualStudioVersion = 17.0.32002.185
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagePipe", "src\MessagePipe\MessagePipe.csproj", "{D94EF9D4-3CC2-4420-8D0B-25957E7C5309}"
EndProject
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public static ValueTask<TMessage> FirstAsync<TMessage>(this ISubscriber<TMessage

Also, the `Func<TMessage, bool>` overload can filter messages by predicate (internally implemented with PredicateFilter, where Order is int.MinValue and is always checked first).

`AsObservable` can convert message pipeline to `IObservable<T>`, it can handle by Reactive Extensions(in Unity, you can use `UniRx`). `AsObervable` exists in sync subscriber(keyless, keyed, buffered).
`AsObservable` can convert message pipeline to `IObservable<T>`, it can handle by Reactive Extensions(in Unity, you can use `UniRx`). `AsObservable` exists in sync subscriber(keyless, keyed, buffered).

`AsAsyncEnumerable` can convert message pipeline to `IAsyncEnumerable<T>`, it can handle by async LINQ and async foreach. `AsAsyncEnumerable` exists in async subscriber(keyless, keyed, buffered).

Expand All @@ -477,11 +477,11 @@ var value = await subscriber.FirstAsync(cts.Token);

Filter
---
Filter system can hook before and after method invocation. It is implemented with the Middleware pattern, which allows you to write synchronous and asynchronous code with similar syntax. MessagePipe's filter kind are sync(`MessageHandlerFilter<T>`) and async(`AsyncMessageHandlerFilter<T>`) and request(`RequestHandlerFilter<TReq, TRes>`) and async request (`AsyncRequestHandlerFilter<TReq, TRes>`), you can inherit theres to implement filter.
Filter system can hook before and after method invocation. It is implemented with the Middleware pattern, which allows you to write synchronous and asynchronous code with similar syntax. MessagePipe provides different filter types - sync (`MessageHandlerFilter<T>`), async (`AsyncMessageHandlerFilter<T>`), request (`RequestHandlerFilter<TReq, TRes>`) and async request (`AsyncRequestHandlerFilter<TReq, TRes>`). To implement other concerete filters the above filter types can be extended.

Filters can be specified in three places. Global(by `MessagePipeOptions.AddGlobalFilter`), per handler type, and per subscribe. The filters are sorted according to the Order specified in each of them, and are generated when subscribing.
Filters can be specified in three places - global(by `MessagePipeOptions.AddGlobalFilter`), per handler type, and per subscription. These filters are sorted according to the Order specified in each of them, and are generated when subscribing.

Since it is generated on a per-subscribe basis, the filter can have a state.
Since the filter is generated on a per subscription basis, the filter can have a state.

```csharp
public class ChangedValueFilter<T> : MessageHandlerFilter<T>
Expand Down Expand Up @@ -959,7 +959,7 @@ async void A(IRemoteRequestHandler<int, string> remoteHandler)
var v = await remoteHandler.InvokeAsync(9999);
Console.WriteLine(v); // ECHO:9999
}
``
```

For Unity, requires to import MessagePack-CSharp package and needs slightly different configuration.

Expand Down Expand Up @@ -1184,6 +1184,9 @@ public class GameLifetimeScope : LifetimeScope
// RegisterMessagePipe returns options.
var options = builder.RegisterMessagePipe(/* configure option */);

// Setup GlobalMessagePipe to enable diagnostics window and global function
builder.RegisterBuildCallback(c => GlobalMessagePipe.SetProvider(c.AsServiceProvider()));

// RegisterMessageBroker: Register for IPublisher<T>/ISubscriber<T>, includes async and buffered.
builder.RegisterMessageBroker<int>(options);

Expand All @@ -1201,13 +1204,10 @@ public class MessagePipeDemo : VContainer.Unity.IStartable
readonly IPublisher<int> publisher;
readonly ISubscriber<int> subscriber;

public MessagePipeDemo(IPublisher<int> publisher, ISubscriber<int> subscriber, IObjectResolver resolver)
public MessagePipeDemo(IPublisher<int> publisher, ISubscriber<int> subscriber)
{
this.publisher = publisher;
this.subscriber = subscriber;

// set global to enable diagnostics window and global function
GlobalMessagePipe.SetProvider(resolver.AsServiceProvider());
}

public void Start()
Expand Down
Loading

0 comments on commit c6af515

Please sign in to comment.