Repository: Fractural/GDTask
Branch: main
Commit: 7e0c911b16cc
Files: 127
Total size: 781.4 KB
Directory structure:
gitextract_fw_63qmu/
├── .github/
│ └── workflows/
│ └── deploy.yml
├── .gitignore
├── .gitmodules
├── GDTask.csproj
├── GDTask.sln
├── LICENSE.md
├── README.md
├── addons/
│ └── GDTask/
│ ├── AsyncLazy.cs
│ ├── AsyncLazy.cs.uid
│ ├── AsyncUnit.cs
│ ├── AsyncUnit.cs.uid
│ ├── Autoload/
│ │ ├── GDTaskPlayerLoopAutoload.cs
│ │ ├── GDTaskPlayerLoopAutoload.cs.uid
│ │ ├── ProcessListener.cs
│ │ └── ProcessListener.cs.uid
│ ├── CancellationTokenEqualityComparer.cs
│ ├── CancellationTokenEqualityComparer.cs.uid
│ ├── CancellationTokenExtensions.cs
│ ├── CancellationTokenExtensions.cs.uid
│ ├── CancellationTokenSourceExtensions.cs
│ ├── CancellationTokenSourceExtensions.cs.uid
│ ├── CompilerServices/
│ │ ├── AsyncGDTaskMethodBuilder.cs
│ │ ├── AsyncGDTaskMethodBuilder.cs.uid
│ │ ├── AsyncGDTaskVoidMethodBuilder.cs
│ │ ├── AsyncGDTaskVoidMethodBuilder.cs.uid
│ │ ├── StateMachineRunner.cs
│ │ └── StateMachineRunner.cs.uid
│ ├── GDTask.Delay.cs
│ ├── GDTask.Delay.cs.uid
│ ├── GDTask.Factory.cs
│ ├── GDTask.Factory.cs.uid
│ ├── GDTask.Run.cs
│ ├── GDTask.Run.cs.uid
│ ├── GDTask.Threading.cs
│ ├── GDTask.Threading.cs.uid
│ ├── GDTask.ToSignal.cs
│ ├── GDTask.ToSignal.cs.uid
│ ├── GDTask.WaitUntil.cs
│ ├── GDTask.WaitUntil.cs.uid
│ ├── GDTask.WhenAll.Generated.cs
│ ├── GDTask.WhenAll.Generated.cs.uid
│ ├── GDTask.WhenAll.cs
│ ├── GDTask.WhenAll.cs.uid
│ ├── GDTask.WhenAny.Generated.cs
│ ├── GDTask.WhenAny.Generated.cs.uid
│ ├── GDTask.WhenAny.cs
│ ├── GDTask.WhenAny.cs.uid
│ ├── GDTask.cs
│ ├── GDTask.cs.uid
│ ├── GDTaskCompletionSource.cs
│ ├── GDTaskCompletionSource.cs.uid
│ ├── GDTaskExtensions.Shorthand.cs
│ ├── GDTaskExtensions.Shorthand.cs.uid
│ ├── GDTaskExtensions.cs
│ ├── GDTaskExtensions.cs.uid
│ ├── GDTaskObservableExtensions.cs
│ ├── GDTaskObservableExtensions.cs.uid
│ ├── GDTaskScheduler.cs
│ ├── GDTaskScheduler.cs.uid
│ ├── GDTaskSynchronizationContext.cs
│ ├── GDTaskSynchronizationContext.cs.uid
│ ├── GDTaskVoid.cs
│ ├── GDTaskVoid.cs.uid
│ ├── IGDTaskSource.cs
│ ├── IGDTaskSource.cs.uid
│ ├── Internal/
│ │ ├── ArrayPool.cs
│ │ ├── ArrayPool.cs.uid
│ │ ├── ArrayPoolUtil.cs
│ │ ├── ArrayPoolUtil.cs.uid
│ │ ├── ArrayUtil.cs
│ │ ├── ArrayUtil.cs.uid
│ │ ├── ContinuationQueue.cs
│ │ ├── ContinuationQueue.cs.uid
│ │ ├── DiagnosticsExtensions.cs
│ │ ├── DiagnosticsExtensions.cs.uid
│ │ ├── Error.cs
│ │ ├── Error.cs.uid
│ │ ├── GodotEqualityComparer.cs
│ │ ├── GodotEqualityComparer.cs.uid
│ │ ├── MinimumQueue.cs
│ │ ├── MinimumQueue.cs.uid
│ │ ├── PlayerLoopRunner.cs
│ │ ├── PlayerLoopRunner.cs.uid
│ │ ├── PooledDelegate.cs
│ │ ├── PooledDelegate.cs.uid
│ │ ├── RuntimeHelpersAbstraction.cs
│ │ ├── RuntimeHelpersAbstraction.cs.uid
│ │ ├── StatePool.cs
│ │ ├── StatePool.cs.uid
│ │ ├── TaskTracker.cs
│ │ ├── TaskTracker.cs.uid
│ │ ├── ValueStopwatch.cs
│ │ ├── ValueStopwatch.cs.uid
│ │ ├── WeakDictionary.cs
│ │ └── WeakDictionary.cs.uid
│ ├── MoveNextSource.cs
│ ├── MoveNextSource.cs.uid
│ ├── PlayerLoopTimer.cs
│ ├── PlayerLoopTimer.cs.uid
│ ├── Progress.cs
│ ├── Progress.cs.uid
│ ├── TaskPool.cs
│ ├── TaskPool.cs.uid
│ ├── TimeoutController.cs
│ ├── TimeoutController.cs.uid
│ ├── TriggerEvent.cs
│ ├── TriggerEvent.cs.uid
│ └── Triggers/
│ ├── AsyncDestroyTrigger.cs
│ ├── AsyncDestroyTrigger.cs.uid
│ ├── AsyncEnterTreeTrigger.cs
│ ├── AsyncEnterTreeTrigger.cs.uid
│ ├── AsyncReadyTrigger.cs
│ ├── AsyncReadyTrigger.cs.uid
│ ├── AsyncTriggerBase.cs
│ ├── AsyncTriggerBase.cs.uid
│ ├── AsyncTriggerExtensions.cs
│ ├── AsyncTriggerExtensions.cs.uid
│ ├── NodeMessagesTriggers.cs
│ └── NodeMessagesTriggers.cs.uid
├── bootsplash.png.import
├── default_env.tres
├── icon.import
├── icon.png.import
├── project.godot
└── tests/
└── manual/
├── Test.cs
├── Test.cs.uid
└── Test.tscn
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/workflows/deploy.yml
================================================
name: 🚀 Deploy Release
on:
push:
branches:
- main
tags:
- "v*.*.*"
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
submodules: recursive
# Deploy to local repo
- name: Deploy to Release Branch
uses: s0/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: release
FOLDER: addons/GDTask
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
run: |
mkdir release
mv addons/GDTask release
pushd release
zip -r ../Release.zip *
popd
- name: Upload Release
uses: actions/upload-artifact@v4
with:
name: Release
path: release
- name: Tagged Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: Release.zip
================================================
FILE: .gitignore
================================================
# Godot 4+ specific ignores
.godot/
# Godot-specific ignores
.import/
export.cfg
export_presets.cfg
# Mono-specific ignores
.mono/
data_*/
# IntelliJ
.idea/
# VSCode Settings
.vscode/
# Visual studio
.vs/
Builds/
# Ignore stub bin and obj folders
bin/
obj/
# Tests
tests/results.xml
tests/metadata.json
# MacOS
.DS_Store
================================================
FILE: .gitmodules
================================================
================================================
FILE: GDTask.csproj
================================================
net8.0
true
================================================
FILE: GDTask.sln
================================================
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35027.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GDTask", "GDTask.csproj", "{CEF6A453-1034-46B7-9617-C94E19891B46}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
ExportDebug|Any CPU = ExportDebug|Any CPU
ExportRelease|Any CPU = ExportRelease|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CEF6A453-1034-46B7-9617-C94E19891B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEF6A453-1034-46B7-9617-C94E19891B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEF6A453-1034-46B7-9617-C94E19891B46}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU
{CEF6A453-1034-46B7-9617-C94E19891B46}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU
{CEF6A453-1034-46B7-9617-C94E19891B46}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU
{CEF6A453-1034-46B7-9617-C94E19891B46}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {688C3662-0D40-4D17-8576-4FA4A992B65A}
EndGlobalSection
EndGlobal
================================================
FILE: LICENSE.md
================================================
The MIT License (MIT)
Copyright (c) 2019 Atlinx, Yoshifumi Kawai / Cysharp, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# ⚠️ Superceded by [GDTask.Nuget](https://github.com/Delsin-Yu/GDTask.Nuget)
This addon has been superceded by [Delsin-Yu's GDTask.Nuget](https://github.com/Delsin-Yu/GDTask.Nuget) package, which is accessible from the Nuget package manager. Their package also contains useful profiling tools for debugging GDTasks.
# GDTask ✅

> [!Note]
>
> This branch is for the Godot 4.4 version of the addon.
> You can download the Godot 3.x version from the 3.x branch.
Adds async/await features in Godot for easier async coding.
Based on code from [Cysharp's UniTask library for Unity](https://github.com/Cysharp/UniTask).
```CSharp
using Fractural.Tasks;
public Test : Node
{
[Signal]
public delegate void MySignalHandler(int number, bool boolean);
public override _Ready()
{
// Running a task from a non-async method.
Run().Forget();
}
public async GDTaskVoid Run()
{
await GDTask.DelayFrame(100);
// Waiting some amount of time
// Note that these delays are paused when the game is paused
await GDTask.Delay(TimeSpan.FromSeconds(10));
await GDTask.Delay(TimeSpan.FromSeconds(10), PlayerLoopTiming.Process);
await GDTask.Delay(TimeSpan.FromSeconds(10), PlayerLoopTiming.PhysicsProcess);
// Waiting some amount of milliseconds
await GDTask.Delay(1000);
// Waiting some amount of milliseconds, regardless of whether the game is paused
await GDTask.Delay(TimeSpan.FromSeconds(10), PlayerLoopTiming.PauseProcess);
await GDTask.Delay(TimeSpan.FromSeconds(10), PlayerLoopTiming.PausePhysicsProcess);
// Awaiting for a signal
WaitAndEmitMySignal(TimeSpan.FromSeconds(2)).Forget();
var signalResults = await GDTask.ToSignal(this, nameof(MySignal));
// signalResults = [10, true]
// Cancellable awaiting a signal
var cts = new CancellationTokenSource();
WaitAndEmitMySignal(TimeSpan.FromSeconds(2)).Forget();
WaitAndCancelToken(TimeSpan.FromSeconds(1), cts).Forget();
try
{
var signalResults = await GDTask.ToSignal(this, nameof(MySignal), cts.Token);
}
catch (OperationCanceledException _)
{
GD.Print("Awaiting MySignal cancelled!");
}
// Waiting a single frame
await GDTask.Yield();
await GDTask.NextFrame();
await GDTask.WaitForEndOfFrame();
// Waiting for specific lifetime call
await GDTask.WaitForPhysicsProcess();
// Cancellation of a GDTask
var cts = new CancellationTokenSource();
CancellableReallyLongTask(cts.Token).Forget();
await GDTask.Delay(TimeSpan.FromSeconds(3));
cts.Cancel();
// Returning a value from a GDTask
string result = await RunWithResult();
return result + " with additional text";
}
public async GDTask RunWithResult()
{
await GDTask.Delay(TimeSpan.FromSeconds(3));
return "A result string";
}
public async GDTaskVoid ReallyLongTask(CancellationToken cancellationToken)
{
GD.Print("Starting long task.");
await GDTask.Delay(TimeSpan.FromSeconds(1000000), cancellationToken: cancellationToken);
GD.Print("Finished long task.");
}
public async GDTaskVoid WaitAndEmitMySignal(TimeSpan delay)
{
await GDTask.Delay(delay);
EmitSignal(nameof(MySignal), 10, true);
}
public async GDTaskVoid WaitAndCancelToken(TimeSpan delay, CancellationTokenSource cts)
{
await GDTask.Delay(delay);
cts.Cancel();
}
}
```
## Installation
Manual
1. Download the repository
2. Move the `addons/GDTask` folder into `addons/GDTask`
Git Submodules
1. Make sure your project has a git repo initialized
2. Run
``` bash
git submodule add -b release https://github.com/fractural/GDTask.git addons/GDTask
```
3. Add `addons/GDTask/Autoload/GDTaskPlayerLoopAutoload` as an autoload
================================================
FILE: addons/GDTask/AsyncLazy.cs
================================================
using System;
using System.Threading;
namespace Fractural.Tasks
{
public partial class AsyncLazy
{
static Action