Show / Hide Table of Contents

Class ThreadSafeActions

Inheritance
System.Object
ThreadSafeActions
Namespace: Eco.Core.Utils
Assembly: Eco.Core.dll
Syntax
public static class ThreadSafeActions : Object

Methods

UpdateSubject<T, TAction>(ref T, T, Action<T, TAction>, Action<T, TAction>, TAction)

Updates subject (action emitter). It uses addAction and removeAction operations for adding action to new subject and removing from the old. It is thread-safe and ensures old subscription removed from subject even in concurrent environment. It possible though that both newSubject and subject subscribed for short period of time. It is very rare case, but you should aware of it. It happens if action removed from old subject, but subject changed in another thread after this, before new subject assigned (it will be removed anyway because of interlocked change, but it may exists for short period of time).

Declaration
public static void UpdateSubject<T, TAction>(ref T subject, T newSubject, Action<T, TAction> addAction, Action<T, TAction> removeAction, TAction action)
    where T : class where TAction : Delegate
Parameters
Type Name Description
T subject
T newSubject
System.Action<T, TAction> addAction
System.Action<T, TAction> removeAction
TAction action
Type Parameters
Name Description
T
TAction

UpdateSubject<T, TAction>(ref T, T, Func<T, ThreadSafeActionBase<TAction>>, TAction)

Updates ThreadSafeActionBase<TAction> subject (action emitter). It is thread-safe and ensures old subscription removed from subject even in concurrent environment. It possible though that both newSubject and subject subscribed. it is very rare case, but you should aware of it. It happens if action removed from old subject, but subject changed in another thread after this, before new subject assigned (it will be removed anyway because of interlocked change, but it may exists for short period of time).

Declaration
public static void UpdateSubject<T, TAction>(ref T subject, T newSubject, Func<T, ThreadSafeActionBase<TAction>> actionAccessor, TAction action)
    where T : class where TAction : Delegate
Parameters
Type Name Description
T subject
T newSubject
System.Func<T, ThreadSafeActionBase<TAction>> actionAccessor
TAction action
Type Parameters
Name Description
T
TAction
☀
☾
In This Article
Back to top
Copyright (c) Strange Loop Games 2021
☀
☾