Announcement

Collapse
No announcement yet.

[OPEN] [#2405] Task.Delay with CancellationToken support

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [OPEN] [#2405] Task.Delay with CancellationToken support

    I noticed CancellationToken is implemented in 15.7.0.0 but the version of System.Threading.Tasks.Task does not support Delay with a CancellationToken as defined here https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Would it be easy to add? Thanks.

  • #2
    Thanks for contacting us, and for the feature request.

    We'll take a look at what would required to support the CancellationToken and get back to you with an update.

    Comment


    • #3
      Created Issue #2405 to track this Feature Request.

      Also created Issue #2406 as a Feature Request with support for Task.Wait Method.
      Last edited by geoffrey.mcgill; 2017-02-17 @ 02:15 AM.

      Comment


      • #4
        I figured out a way to implement it all in the C# side. It just wraps the JS methods so it could also be useful when implementing the bridge version

                public static Task<bool> Delay(int durationMs, CancellationToken cancellationToken)
                {
                    var completionSource = new TaskCompletionSource<bool>();
        
                    int id = Global.SetTimeout(() =>
                    {
                        completionSource.SetResult(true);
                    }, durationMs);
        
                    cancellationToken.Register(() =>
                    {
                        Global.ClearTimeout(id);
                        completionSource.TrySetResult(false);
                    });
        
                    return completionSource.Task;
                }
        This version returns true if the delay ran its entire duration and false if it was cancelled early.
        Last edited by MarkT; 2017-02-17 @ 04:04 PM.

        Comment

        Working...
        X