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

UpdateHandle - Investigate supporting async/await #133

Open
mbaker3 opened this issue Nov 8, 2022 · 0 comments
Open

UpdateHandle - Investigate supporting async/await #133

mbaker3 opened this issue Nov 8, 2022 · 0 comments
Labels
effort-intense Sleep on it - 16 to 40 hours priority-medium Standard task, plan as you see fit. status-backlog Tasks captured but not yet planned. type-feature New feature or request

Comments

@mbaker3
Copy link
Member

mbaker3 commented Nov 8, 2022

Investigate whether supporting the ability to await on update events and intervals/timeouts is performant and feasible.

Desired API

private async void MyMethod()
{
   await m_UpdateHandle.CallAfter(1.5f, UpdateHandle.FixedDeltaProvider);
   await m_UpdateHandle.CallAfterUpdates(1);
   await m_UpdateHandle.OnUpdateAwaiter;
}

Questions

  • Does this approach perform similarly to the existing callback/event based API?
  • Do async methods resume execution on their own thread or on the thread of their await target?
    • We need the methods to resume on the same thread that the update handle calls on. Many applications use update handles to marshal calls back onto their main thread.

TaskCompletionSource vs SemaphoreSlim

Which is lighter weight and the better way to go?

TaskCompletionSource

private Task WaitOnUpdate()
{
    //TODO: Substitute for non-generic in .NET5 - https://github.com/dotnet/runtime/pull/37452
    TaskCompletionSource<bool> completionSource = new TaskCompletionSource<bool>();
    updateHandle.OnUpdate += () =>
    {
        completionSource.TrySetResult(true);
    };

    return completionSource.Task;
}

SemaphoreSlim

private Task WaitOnUpdate()
{
    SemaphoreSlim semaphore = new SemaphoreSlim(0, 1);
    updateHandle.OnUpdate += () =>
    {
        semaphore.Release();
    };

    return semaphore.WaitAsync();
}
@mbaker3 mbaker3 added effort-intense Sleep on it - 16 to 40 hours priority-medium Standard task, plan as you see fit. status-backlog Tasks captured but not yet planned. type-feature New feature or request labels Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort-intense Sleep on it - 16 to 40 hours priority-medium Standard task, plan as you see fit. status-backlog Tasks captured but not yet planned. type-feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant