MegaBites-AI/Windows-powershell
0372
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Threading;5 6using Dbg = System.Management.Automation.Diagnostics;7 8namespace System.Management.Automation.Remoting9{10 /// <summary>11 /// Blocks caller trying to get the value of an object of type T12 /// until the value is set. After the set all future gets are13 /// unblocked.14 /// </summary>15 internal class AsyncObject<T> where T : class16 {17 /// <summary>18 /// Value.19 /// </summary>20 private T _value;21 22 /// <summary>23 /// Value was set.24 /// </summary>25 private readonly ManualResetEvent _valueWasSet;26 27 /// <summary>28 /// Value.29 /// </summary>30 internal T Value31 {32 get33 {34 bool result = _valueWasSet.WaitOne();35 if (!result)36 {37 _value = null;38 }39 40 return _value;41 }42 43 set44 {45 _value = value;46 _valueWasSet.Set();47 }48 }49 50 /// <summary>51 /// Constructor for AsyncObject.52 /// </summary>53 internal AsyncObject()54 {55 _valueWasSet = new ManualResetEvent(false);56 }57 }58}59 