Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When to Dispose Async #56

Closed
oliverw opened this issue Sep 1, 2017 · 2 comments
Closed

When to Dispose Async #56

oliverw opened this issue Sep 1, 2017 · 2 comments
Labels

Comments

@oliverw
Copy link

oliverw commented Sep 1, 2017

Is it valid to Dispose an Async Handle within its callback like this?:

var disposer = loop.CreateAsync((handle) =>
{
    tcp.Dispose();

    handle.Dispose();
});

The purpose of this example is to schedule the disposal of another loop-bound resource on the loop thread.

@StormHub
Copy link
Owner

StormHub commented Sep 1, 2017

Yes it is, normal once off running for async handle.
There are some cases where you need to worry about closure, I typically do something like this:

        asyncHandle = this.loop.CreateAsync(
            handle =>
            {
                var disposible = handle.UserToken as IDisposable;
                disposible?.Dispose();
                handle.Dispose();
            });
        asyncHandle.UserToken = tcp;   // Save to the handle cookie
        asyncHandle.Send();

@oliverw
Copy link
Author

oliverw commented Sep 1, 2017

Thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants