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
1 changed files with 6 additions and 3 deletions

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);
}
}
}