From 6fbb4b89885b0708c1de0851ea663fa5309087cc Mon Sep 17 00:00:00 2001 From: Tomasz Janczuk Date: Fri, 29 Mar 2013 09:19:35 -0700 Subject: [PATCH] fix race condition in sample --- samples/111_clr_listener.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/samples/111_clr_listener.js b/samples/111_clr_listener.js index 0624ac2f..6ec1bd32 100644 --- a/samples/111_clr_listener.js +++ b/samples/111_clr_listener.js @@ -15,8 +15,7 @@ var createController = edge.func(function () {/* { return new { yieldControl = (Func>)((i) => { - Startup.AcquireControl(); - return Startup.tcs.Task; + return Startup.AcquireControl(); }), regainControl = (Func>)(async (i) => { Startup.ReleaseControl(); @@ -25,7 +24,7 @@ var createController = edge.func(function () {/* }; } - static void AcquireControl() + static Task AcquireControl() { // single threaded; always called on V8 thread @@ -34,7 +33,9 @@ var createController = edge.func(function () {/* throw new InvalidOperationException("CLR already controls the lifetime of the process."); } - tcs = new TaskCompletionSource(); + TaskCompletionSource tmp = new TaskCompletionSource(); + tcs = tmp; + return tmp.Task; } public static void ReleaseControl()