Announcement

Collapse
No announcement yet.

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

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

    [CLOSED] [#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.
    Last edited by fabricio.murta; 2019-05-21 @ 10:39 PM.

    #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 @ 03: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 @ 05:04 PM.

        Comment


          #5
          Hello, @MarkT!

          Both feature issues #2405 and #2406 have been implemented and will be available next Bridge release! Currently we have it set to be 17.8.0.

          Thanks again for letting us know about the need for it!

          Comment

          Working...
          X