Open personball opened 3 days ago
And now, I can use TaskCompletionSource
to do some workaround...
private TaskCompletionSource _taskCompletionSource = new(); // one time per await
...
public void CreateNextTask(ProjectTask upstream, string nextTaskType, LuaFunction? callback = null)
{
CreateNextProjectTaskAsync(upstream, nextTaskType).ContinueWith(t =>
{
var res = t.Result;
callback?.Call(res.Item1, res.Item2);
_taskCompletionSource.SetResult();
});
}
[Fact]
public async Task HandleTaskFinished()
{
...
var actionResults = lua.DoString(action);
await _taskCompletionSource.Task;// wait until _taskCompletionSource.SetResult(); called.
var x = lua["x"]; // Test
x.ShouldBe("Test");
var y = lua["y"]; // Test
y.ShouldBe("Test");
lua.State.Status.ShouldBe(KeraLua.LuaStatus.OK);
}
Hi, after I search of 'async await' in issues, with #514 #295 #52
I know how to do a callback when lua invoke a async C# method with
ContinueWith
.But, it is really a 'fire and forgot' invocation. The call stack will not back to the top caller.
How can I do a real one
await
when invokingDoString()
?Here is codes reproduce it:
ProjectTask
could be any class with aGuid Id
andstring TaskName
.