Skip to content

Commit

Permalink
Set Rust callbacks to complete tasks asynchronously (temporalio#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
cretz authored Jun 18, 2024
1 parent c0058a1 commit a871164
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/Temporalio/Bridge/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public static async Task<Client> ConnectAsync(
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<Client>();
var completion = new TaskCompletionSource<Client>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.client_connect(
Expand Down Expand Up @@ -125,7 +126,8 @@ public async Task<T> CallAsync<T>(
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<ByteArray>();
var completion = new TaskCompletionSource<ByteArray>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.client_rpc_call(
Expand Down
9 changes: 6 additions & 3 deletions src/Temporalio/Bridge/EphemeralServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public static async Task<EphemeralServer> StartTemporaliteAsync(
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<EphemeralServer>();
var completion = new TaskCompletionSource<EphemeralServer>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.ephemeral_server_start_dev_server(
Expand All @@ -76,7 +77,8 @@ public static async Task<EphemeralServer> StartTestServerAsync(
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<EphemeralServer>();
var completion = new TaskCompletionSource<EphemeralServer>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.ephemeral_server_start_test_server(
Expand All @@ -97,7 +99,8 @@ public async Task ShutdownAsync()
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<bool>();
var completion = new TaskCompletionSource<bool>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.ephemeral_server_shutdown(
Expand Down
18 changes: 12 additions & 6 deletions src/Temporalio/Bridge/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public async Task ValidateAsync()
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<bool>();
var completion = new TaskCompletionSource<bool>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.worker_validate(
Expand Down Expand Up @@ -141,7 +142,8 @@ public void ReplaceClient(Client client)
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<ByteArray?>();
var completion = new TaskCompletionSource<ByteArray?>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.worker_poll_workflow_activation(
Expand Down Expand Up @@ -179,7 +181,8 @@ public void ReplaceClient(Client client)
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<ByteArray?>();
var completion = new TaskCompletionSource<ByteArray?>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.worker_poll_activity_task(
Expand Down Expand Up @@ -218,7 +221,8 @@ public async Task CompleteWorkflowActivationAsync(
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<bool>();
var completion = new TaskCompletionSource<bool>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.worker_complete_workflow_activation(
Expand Down Expand Up @@ -252,7 +256,8 @@ public async Task CompleteActivityTaskAsync(Api.ActivityTaskCompletion comp)
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<bool>();
var completion = new TaskCompletionSource<bool>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.worker_complete_activity_task(
Expand Down Expand Up @@ -338,7 +343,8 @@ public async Task FinalizeShutdownAsync()
{
using (var scope = new Scope())
{
var completion = new TaskCompletionSource<bool>();
var completion = new TaskCompletionSource<bool>(
TaskCreationOptions.RunContinuationsAsynchronously);
unsafe
{
Interop.Methods.worker_finalize_shutdown(
Expand Down

0 comments on commit a871164

Please sign in to comment.