System.Threading.Tasks.TaskCompletionSource.SetResult(TOut)

Here are the examples of the csharp api System.Threading.Tasks.TaskCompletionSource.SetResult(TOut) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

19 Source : AsyncGate.cs
with MIT License
from Azure

public void Release(TOut value = default)
        {
            lock (_sync)
            {
                Reset().SetResult(value);
            }
        }

19 Source : IoApiSet.Threading.cs
with MIT License
from dahall

private static unsafe Task<TOut?> ExplicitDeviceIoControlAsync<TIn, TOut>(HFILE hDevice, uint ioControlCode, TIn? inVal, TOut? outVal) where TIn : struct where TOut : struct
		{
#pragma warning disable CS0618 // Type or member is obsolete
			ThreadPool.BindHandle((IntPtr)hDevice);
#pragma warning restore CS0618 // Type or member is obsolete
			var tcs = new TaskCompletionSource<TOut?>();
			var buffer = Pack(inVal, outVal);
			var nativeOverlapped = new Overlapped().Pack((code, bytes, overlap) =>
			{
				try
				{
					switch (code)
					{
						case Win32Error.ERROR_SUCCESS:
							outVal = Unpack<TIn, TOut>(buffer).Item2;
							tcs.TrySetResult(outVal);
							break;

						case Win32Error.ERROR_OPERATION_ABORTED:
							tcs.TrySetCanceled();
							break;

						default:
							tcs.TrySetException(new Win32Exception((int)code));
							break;
					}
				}
				finally
				{
					Overlapped.Unpack(overlap);
					Overlapped.Free(overlap);
				}
			}, buffer);

			var unpack = true;
			try
			{
				var inSz = Marshal.SizeOf(typeof(TIn));
				fixed (byte* pIn = buffer, pOut = &buffer[inSz])
				{
					var ret = DeviceIoControl(hDevice, ioControlCode, pIn, (uint)inSz, pOut, (uint)(buffer.Length - inSz), out var bRet,
						nativeOverlapped);
					if (ret)
					{
						outVal = Unpack<TIn, TOut>(buffer).Item2;
						tcs.SetResult(outVal);
						return tcs.Task;
					}
				}

				var lastWin32Error = Marshal.GetLastWin32Error();
				if (lastWin32Error != Win32Error.ERROR_IO_PENDING && lastWin32Error != Win32Error.ERROR_SUCCESS)
					throw new Win32Exception(lastWin32Error);
				unpack = false;
				return tcs.Task;
			}
			finally
			{
				if (unpack)
				{
					Overlapped.Unpack(nativeOverlapped);
					Overlapped.Free(nativeOverlapped);
				}
			}
		}

19 Source : DisruptorSimpleAwaitable.cs
with MIT License
from michaelscodingspot

public void OnEvent(StepPayload<TOut> payload)
        {
            if (payload.TaskCompletionSource.Task.IsFaulted)
                return;
            payload.TaskCompletionSource.SetResult((TOut)payload.Value);
        }

19 Source : DisruptorPipelineBuilder.cs
with MIT License
from michaelscodingspot

public void OnEvent(DisruptorEvent data, long sequence, bool endOfBatch)
            {
                var tcs = (TaskCompletionSource<TOut>)data.TaskCompletionSource;
                tcs.SetResult(data.Read<TOut>());
            }

19 Source : AsyncGate.cs
with MIT License
from microsoft

public void Release(TOut value = default)
        {
            lock (_sync)
            {
                Reset().SetResult(value);
            }
        }