Skip to content

Commit

Permalink
Merge pull request #45 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.42
  • Loading branch information
uurha committed Aug 17, 2024
1 parent 98ab46a commit 3f302e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions Runtime/Utility/TaskUtility.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;

namespace Better.Commons.Runtime.Utility
{
public static class TaskUtility
{
public static Task WaitForSeconds(float seconds, CancellationToken cancellationToken = default)
public static async Task WaitForSeconds(float seconds, CancellationToken cancellationToken = default)
{
if (seconds <= 0 || cancellationToken.IsCancellationRequested)
{
return;
}

while (seconds > 0 && !cancellationToken.IsCancellationRequested)
{
await Task.Yield();
seconds -= Time.unscaledDeltaTime;
}
}

public static Task Delay(float seconds, CancellationToken cancellationToken = default)
{
if (seconds <= 0 || cancellationToken.IsCancellationRequested)
{
return Task.CompletedTask;
}

var millisecondsDelay = TimeUtility.SecondsToMilliseconds(seconds);
return Task.Delay(millisecondsDelay, cancellationToken);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.tdw.better.commons",
"displayName": "Better Commons",
"version": "0.0.41",
"version": "0.0.42",
"unity": "2021.3",
"description": " ",
"dependencies": {
Expand Down

0 comments on commit 3f302e8

Please sign in to comment.