Skip to content

Async wrapper #14

Description

@tstenner

To me it also makes sense to wrap pull_sample (and even more especially resolve_streams) into async methods because it is a very convenient way to kick off a method that handles samples as they come in in the background. When a C# method hits await, it returns control to the caller. Then, anything that happens after await will kick off automagically once the task is complete:

private async Task PullAndProcessAsync()
{
    await Task.Run(()=>pull_sample(...));
   // at this point the caller is back on
   ProcessNewData(...);
   // processing of data is happening outside of, say, GUI thread
}

Waiting on IO is exactly what async methods that return Task are meant for. CPU intensive tasks are meant to return Task. This also goes hand in hand with leaning on C# to handle allocating buffers and collecting garbage instead of the C-style array arguments for the output from pull_sample/chunk.

I am not sure if the best thing to do is to leave this library as it is and simply add a class that wraps everything in async methods, or just to roll a new wrapper. People are already using this one, but it is rather 2009.

Originally posted by @dmedine in #12 (comment)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions