danbarua / NEventSocket

A reactive FreeSwitch eventsocket library for Modern .Net
Mozilla Public License 2.0
73 stars 37 forks source link

Long-running applications block new Outbound connections #14

Closed danbarua closed 9 years ago

danbarua commented 9 years ago

In scriptcs, where async/await is not available, calling .Wait() on a long-running dial plan application such as conference or refer in the connections observable subscription blocks new connections.

Example:

using (var listener = new OutboundListener(8084))
{
  var sub = listener.Connections.SubscribeOn(TaskPoolScheduler.Default).Subscribe(
    socket => {
      socket.Connect().Wait();
      var uuid = socket.ChannelData.Headers[HeaderNames.UniqueId];

      socket.SubscribeEvents().Wait();
      socket.ExecuteApplication(uuid, "answer").Wait();
      socket.ExecuteApplication(uuid, "conference", "test+1234").Wait(); //blocks
      //socket.ExecuteApplication(uuid, "conference", "test+1234"); //does not block
    });

  listener.Start();

  Console.WriteLine("Press [Enter] to exit.");
  Console.ReadLine();

  sub.Dispose();
}
danbarua commented 9 years ago

Fix - use scriptcs -modules mono and just use async/await instead of .Wait()