summaryrefslogtreecommitdiff
path: root/lib/infrastructure/threading/SynchronousCommandProcessor.cs
blob: c3263f29d6d3a2b5f3f24cc658ee055bf4b1ffad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using jive.utility;

namespace jive.infrastructure.threading
{
  public class SynchronousCommandProcessor : CommandProcessor
  {
    readonly Queue<Command> queued_commands;

    public SynchronousCommandProcessor()
    {
      queued_commands = new Queue<Command>();
    }

    public void add(Action command)
    {
      add(new AnonymousCommand(command));
    }

    public void add(Command command_to_process)
    {
      queued_commands.Enqueue(command_to_process);
    }

    public void run()
    {
      while (queued_commands.Count > 0) queued_commands.Dequeue().run();
    }

    public void stop()
    {
      queued_commands.Clear();
    }
  }
}