microsoft / ClearScript

A library for adding scripting to .NET applications. Supports V8 (Windows, Linux, macOS) and JScript/VBScript (Windows).
https://microsoft.github.io/ClearScript/
MIT License
1.74k stars 148 forks source link

Client code run completed event. #474

Closed stone89son closed 1 year ago

stone89son commented 1 year ago

Hi everyone. In V8ScriptEngine . on Host code (C#) how to do know Client code has completed excuted and include asynchronous task (http request, sleep, setTimeout)? thank for help me.

ClearScriptLib commented 1 year ago

Hi @stone89son,

As you mentioned, there are several ways for script code to be operating asynchronously, including via direct invocation of managed async methods, blocking calls, etc. – and any number of such operations can be in flight simultaneously.

Therefore, generally speaking, there are no shortcuts. The host and script engine must work together if synchronization is required. For example, the host can hand the script code an event to set when it's done. Alternatively, the script code can give the host a promise or task that tracks the progress of the operation in question.

Good luck!

stone89son commented 1 year ago

thank you for help me and reply. i clear.