Is there any way (on WASM side) to await for an async method to complete when the method returns JS Promise? The async/await keywords require native Task. An example where you might need that is the Blob/File.arrayBuffer() method. In JS you can simply write:
var buffer = await blob.arrayBuffer();
but I cannot find a way to do so on the WASM side.
class method FutureToAsync(aValue: dynamic): Task<dynamic>;
begin
var lCP := new TaskCompletionSource<dynamic>;
result := lCP.Task;
var lCall, lExCall: WebAssemblyDelegate;
lCall := b -> begin
lCP.SetResult(b);
SimpleGC.ForceRelease(IntPtr(InternalCalls.Cast(lCP)));
SimpleGC.ForceRelease(IntPtr(InternalCalls.Cast(lCall)));
SimpleGC.ForceRelease(IntPtr(InternalCalls.Cast(lExCall)));
end;
lExCall := b -> begin
lCP.SetException(new Exception(String(b:ToString())));
SimpleGC.ForceRelease(IntPtr(InternalCalls.Cast(lCP)));
SimpleGC.ForceRelease(IntPtr(InternalCalls.Cast(lCall)));
SimpleGC.ForceRelease(IntPtr(InternalCalls.Cast(lExCall)));
end;
SimpleGC.ForceAddRef(IntPtr(InternalCalls.Cast(lCP)));
SimpleGC.ForceAddRef(IntPtr(InternalCalls.Cast(lCall)));
SimpleGC.ForceAddRef(IntPtr(InternalCalls.Cast(lExCall)));
aValue.then(lCall, lExCall);
end;
Great! Just so you know, the wrapper doesn’t seem to work, I did what you said and I keep getting null as the result. But never mind, I’ll wait for the friday’s build.