2022-06-23 20:45:41 +04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Ragon.Core;
|
|
|
|
|
|
2022-06-25 11:08:50 +04:00
|
|
|
public class Dispatcher: IDispatcher, IDispatcherInternal
|
2022-06-23 20:45:41 +04:00
|
|
|
{
|
2022-06-25 11:08:50 +04:00
|
|
|
public Queue<Action> _actions = new Queue<Action>();
|
|
|
|
|
|
2022-06-23 20:45:41 +04:00
|
|
|
public void Dispatch(Action action)
|
|
|
|
|
{
|
|
|
|
|
lock (_actions)
|
2022-06-25 11:08:50 +04:00
|
|
|
_actions.Enqueue(action);
|
2022-06-23 20:45:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Process()
|
|
|
|
|
{
|
|
|
|
|
lock(_actions)
|
|
|
|
|
while(_actions.TryDequeue(out var action))
|
2022-06-25 11:08:50 +04:00
|
|
|
action?.Invoke();
|
2022-06-23 20:45:41 +04:00
|
|
|
}
|
|
|
|
|
}
|