mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Reactive.Linq;
|
|
using System.Reactive.Subjects;
|
|
|
|
namespace Squidex.Infrastructure
|
|
{
|
|
public sealed class InMemoryPubSub : IPubSub
|
|
{
|
|
private readonly Subject<object> subject = new Subject<object>();
|
|
private readonly bool publishAlways;
|
|
|
|
public InMemoryPubSub()
|
|
{
|
|
}
|
|
|
|
public InMemoryPubSub(bool publishAlways)
|
|
{
|
|
this.publishAlways = publishAlways;
|
|
}
|
|
|
|
public void Publish<T>(T value, bool notifySelf)
|
|
{
|
|
if (notifySelf || publishAlways)
|
|
{
|
|
subject.OnNext(value);
|
|
}
|
|
}
|
|
|
|
public IDisposable Subscribe<T>(Action<T> handler)
|
|
{
|
|
return subject.Where(x => x is T).OfType<T>().Subscribe(handler);
|
|
}
|
|
}
|
|
}
|
|
|