Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Update TaskExtensions.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
uurha committed Feb 11, 2024
1 parent e437b7c commit 1b24e6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Better.Extensions.Runtime.TasksExtension
{
public static class TaskExtensions
{
/// <summary>
/// Blocks while condition is true or timeout occurs.
/// Blocks while condition is true or timeout occurs.
/// </summary>
/// <param name="condition">The condition that will perpetuate the block.</param>
/// <param name="frequency">The frequency at which the condition will be check, in milliseconds.</param>
Expand All @@ -17,15 +18,15 @@ public static async Task WaitWhile(Func<bool> condition, int frequency = 25, int
{
var waitTask = Task.Run(async () =>
{
while (condition())
while (condition())
await Task.Delay(frequency);
});
if (waitTask != await Task.WhenAny(waitTask, Task.Delay(timeout)))
if (waitTask != await Task.WhenAny(waitTask, Task.Delay(timeout)))
throw new TimeoutException();
}

/// <summary>
/// Blocks until condition is true or timeout occurs.
/// Blocks until condition is true or timeout occurs.
/// </summary>
/// <param name="condition">The break condition.</param>
/// <param name="frequency">The frequency at which the condition will be checked.</param>
Expand All @@ -35,7 +36,7 @@ public static async Task WaitUntil(Func<bool> condition, int frequency = 25, int
{
var waitTask = Task.Run(async () =>
{
while (!condition())
while (!condition())
await Task.Delay(frequency);
});

Expand All @@ -44,7 +45,7 @@ public static async Task WaitUntil(Func<bool> condition, int frequency = 25, int
}

/// <summary>
/// Creates task with factory method
/// Creates task with factory method
/// </summary>
/// <param name="action"></param>
/// <typeparam name="T"></typeparam>
Expand All @@ -53,5 +54,10 @@ public static Task<T> CreateTask<T>(this Func<T> action)
{
return Task<T>.Factory.StartNew(action);
}

public static Task WhenAll(this IEnumerable<Task> tasks)
{
return Task.WhenAll(tasks);
}
}
}
2 changes: 1 addition & 1 deletion Assets/BetterExtensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.uurha.betterextensions",
"displayName": "Better Extensions",
"description": "Unity extensions, serialize extension, async extension, string extension and UI extensions",
"version": "1.1.96",
"version": "1.1.97",
"unity": "2020.1",
"author": {
"name": "Better Plugins",
Expand Down

0 comments on commit 1b24e6f

Please sign in to comment.