Selaa lähdekoodia

Introduce Advanced API and ProcessTasks (#1499)

Marko Lahma 2 vuotta sitten
vanhempi
commit
98c7f0b9f0
3 muutettua tiedostoa jossa 37 lisäystä ja 0 poistoa
  1. 11 0
      Jint.Tests.PublicInterface/AdvancedApiTests.cs
  2. 24 0
      Jint/Engine.Advanced.cs
  3. 2 0
      Jint/Engine.cs

+ 11 - 0
Jint.Tests.PublicInterface/AdvancedApiTests.cs

@@ -0,0 +1,11 @@
+namespace Jint.Tests.PublicInterface;
+
+public class AdvancedApiTests
+{
+    [Fact]
+    public void CanProcessTasks()
+    {
+        var engine = new Engine();
+        engine.Advanced.ProcessTasks();
+    }
+}

+ 24 - 0
Jint/Engine.Advanced.cs

@@ -0,0 +1,24 @@
+namespace Jint;
+
+public partial class Engine
+{
+    public AdvancedOperations Advanced { get; }
+}
+
+public class AdvancedOperations
+{
+    private readonly Engine _engine;
+
+    public AdvancedOperations(Engine engine)
+    {
+        _engine = engine;
+    }
+
+    /// <summary>
+    /// Forcefully processes the current task queues (micro and regular), this API may break and change behavior!
+    /// </summary>
+    public void ProcessTasks()
+    {
+        _engine.RunAvailableContinuations();
+    }
+}

+ 2 - 0
Jint/Engine.cs

@@ -96,6 +96,8 @@ namespace Jint
         /// <remarks>The provided engine instance in callback is not guaranteed to be fully configured</remarks>
         public Engine(Action<Engine, Options> options)
         {
+            Advanced = new AdvancedOperations(this);
+
             _executionContexts = new ExecutionContextStack(2);
 
             Options = new Options();