summaryrefslogtreecommitdiff
path: root/lib/SynchronousCommandProcessor.cs
blob: bbd7756f51ee274d16979d3d8ce15788e04ced53 (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
using System;
using System.Collections.Generic;

namespace jive
{
  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();
    }
  }
}