Beispiel #1
0
    protected override void Main()
    {
      TraceDescription(Instructions.MulticastLab);

      int current = 0;

      IObservable<int> source = Observable
        .Interval(TimeSpan.FromSeconds(1))
        .Select(_ => current++)
        .Multicast(() => new ReplaySubject<int>())
        .RefCount();

      using (var disposables = new CompositeDisposable())
      {
        do
        {
          var key = WaitForKey();

          switch (key.KeyChar)
          {
            case '+':
            case '=':
              var id = (char)('A' + disposables.Count);

              var subscription = source.Subscribe(ConsoleOutput(id.ToString()));

              disposables.Add(subscription);
              break;
            case '-':
            case '_':
              if (disposables.Count > 0)
              {
                disposables.Remove(disposables.Last());
              }
              break;
            default:
              return;
          }
        }
        while (true);
      }
    }