1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-23 00:18:47 +00:00

Return Task<bool> for WaitHandle.WaitOneAsync

This commit is contained in:
Oliver Booth 2021-06-27 13:08:58 +01:00
parent 4828300076
commit e8ef1cd028

View File

@ -13,15 +13,18 @@ namespace X10D
/// Returns a <see cref="Task" /> which can be awaited until the current <see cref="WaitHandle" /> receives a signal.
/// </summary>
/// <param name="handle">The <see cref="WaitHandle" /> instance.</param>
/// <returns>A task which encapsulates <see cref="WaitHandle.WaitOne()" />.</returns>
public static Task WaitOneAsync(this WaitHandle handle)
/// <returns>
/// <see langword="true" /> if the current instance receives a signal. If the current instance is never signaled,
/// <see cref="WaitOneAsync" /> never returns.
/// </returns>
public static Task<bool> WaitOneAsync(this WaitHandle handle)
{
if (handle is null)
{
throw new ArgumentNullException(nameof(handle));
}
return new Task(() => handle.WaitOne());
return Task.Run(handle.WaitOne);
}
}
}