Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@davidfowl
Last active July 18, 2020 19:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidfowl/7bbad5e7800573efe93c3e735f2d832a to your computer and use it in GitHub Desktop.
Save davidfowl/7bbad5e7800573efe93c3e735f2d832a to your computer and use it in GitHub Desktop.
var state = new State();
var queue = new QueueClient();
try
{
    var item = await queue.DequeueAsync();
    state.Item = item;
}
catch (Exception ex) when (ex is SomethingException)
{
    state.Item = null;
    state.Exception = ex;
}
finally 
{
   
}

Callbacks:

public class Handler
{
   public State state = new State();
   
   public Task OnItemAsync(Item item)
   {
      state.Item = item;
   }
   
   public Task OnExceptionAsync(Exception ex)
   {
      if (ex is SomethingException)
      {
        state.Item = null;
        state.Exception = ex;
      }
   }
}

var handler = new Handler();
var queue = new QueueClient();
queue.RegisterHandler(handler.OnItemAsync, handler.OnExceptionAsync);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment