Skip to content

Commit

Permalink
✨ Improve WebSocket connections (#186)
Browse files Browse the repository at this point in the history
* ✨ Add OnWebSocketConnect event

* ✨ Add localnet Cluster with default rpc and streaming endpoint

* ⬆️ Update UniTask

* ⬆️ Upgrade NativeWebSocket

* ⬆️ Upgrade Packages/Solana.Unity.Rpc

* 🔥 Remove uneeded dispacther

* ✨ Use processed commitment for faster updates

* ♻️ Update example

* ♻️ Code Refactor
  • Loading branch information
GabrielePicco authored Nov 12, 2023
1 parent 973ba38 commit 2d8eb8b
Show file tree
Hide file tree
Showing 202 changed files with 1,397 additions and 559 deletions.
Binary file modified Packages/NativeWebSocket.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion Packages/NativeWebSocket.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Packages/Solana.Unity.Rpc.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Editor/SplitterGUILayout.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Editor/UniTask.Editor.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Runtime/AsyncLazy.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Runtime/AsyncUnit.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Runtime/Channel.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Runtime/CompilerServices.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Runtime/External.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Runtime/External/Addressables.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public static UniTask WithCancellation(this AsyncOperationHandle handle, Cancell
return ToUniTask(handle, cancellationToken: cancellationToken);
}

public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken, bool cancelImmediately)
{
return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately);
}

public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)
{
if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled(cancellationToken);

Expand All @@ -44,7 +49,7 @@ public static UniTask WithCancellation(this AsyncOperationHandle handle, Cancell
return UniTask.CompletedTask;
}

return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, out var token), token);
return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, cancelImmediately, out var token), token);
}

public struct AsyncOperationHandleAwaiter : ICriticalNotifyCompletion
Expand Down Expand Up @@ -106,6 +111,7 @@ static AsyncOperationHandleConfiguredSource()
readonly Action<AsyncOperationHandle> continuationAction;
AsyncOperationHandle handle;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
IProgress<float> progress;
bool completed;

Expand All @@ -116,7 +122,7 @@ static AsyncOperationHandleConfiguredSource()
continuationAction = Continuation;
}

public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, out short token)
public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, bool cancelImmediately, out short token)
{
if (cancellationToken.IsCancellationRequested)
{
Expand All @@ -132,6 +138,15 @@ public static IUniTaskSource Create(AsyncOperationHandle handle, PlayerLoopTimin
result.progress = progress;
result.cancellationToken = cancellationToken;
result.completed = false;

if (cancelImmediately && cancellationToken.CanBeCanceled)
{
result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
{
var promise = (AsyncOperationHandleConfiguredSource)state;
promise.core.TrySetCanceled(promise.cancellationToken);
}, result);
}

TaskTracker.TrackActiveTask(result, 3);

Expand Down Expand Up @@ -219,6 +234,7 @@ bool TryReturn()
handle = default;
progress = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
return pool.TryPush(this);
}
}
Expand All @@ -237,7 +253,12 @@ public static UniTask<T> WithCancellation<T>(this AsyncOperationHandle<T> handle
return ToUniTask(handle, cancellationToken: cancellationToken);
}

public static UniTask<T> ToUniTask<T>(this AsyncOperationHandle<T> handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
public static UniTask<T> WithCancellation<T>(this AsyncOperationHandle<T> handle, CancellationToken cancellationToken, bool cancelImmediately)
{
return ToUniTask(handle, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately);
}

public static UniTask<T> ToUniTask<T>(this AsyncOperationHandle<T> handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)
{
if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled<T>(cancellationToken);

Expand All @@ -255,7 +276,7 @@ public static UniTask<T> WithCancellation<T>(this AsyncOperationHandle<T> handle
return UniTask.FromResult(handle.Result);
}

return new UniTask<T>(AsyncOperationHandleConfiguredSource<T>.Create(handle, timing, progress, cancellationToken, out var token), token);
return new UniTask<T>(AsyncOperationHandleConfiguredSource<T>.Create(handle, timing, progress, cancellationToken, cancelImmediately, out var token), token);
}

sealed class AsyncOperationHandleConfiguredSource<T> : IUniTaskSource<T>, IPlayerLoopItem, ITaskPoolNode<AsyncOperationHandleConfiguredSource<T>>
Expand All @@ -272,6 +293,7 @@ static AsyncOperationHandleConfiguredSource()
readonly Action<AsyncOperationHandle<T>> continuationAction;
AsyncOperationHandle<T> handle;
CancellationToken cancellationToken;
CancellationTokenRegistration cancellationTokenRegistration;
IProgress<float> progress;
bool completed;

Expand All @@ -282,7 +304,7 @@ static AsyncOperationHandleConfiguredSource()
continuationAction = Continuation;
}

public static IUniTaskSource<T> Create(AsyncOperationHandle<T> handle, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, out short token)
public static IUniTaskSource<T> Create(AsyncOperationHandle<T> handle, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, bool cancelImmediately, out short token)
{
if (cancellationToken.IsCancellationRequested)
{
Expand All @@ -298,6 +320,15 @@ public static IUniTaskSource<T> Create(AsyncOperationHandle<T> handle, PlayerLoo
result.cancellationToken = cancellationToken;
result.completed = false;
result.progress = progress;

if (cancelImmediately && cancellationToken.CanBeCanceled)
{
result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
{
var promise = (AsyncOperationHandleConfiguredSource<T>)state;
promise.core.TrySetCanceled(promise.cancellationToken);
}, result);
}

TaskTracker.TrackActiveTask(result, 3);

Expand Down Expand Up @@ -390,6 +421,7 @@ bool TryReturn()
handle = default;
progress = default;
cancellationToken = default;
cancellationTokenRegistration.Dispose();
return pool.TryPush(this);
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Plugins/UniTask/Runtime/External/DOTween.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2d8eb8b

Please sign in to comment.