Skip to content

Commit b99ff2a

Browse files
committed
Use new AngleSharp exposed feature
1 parent 6bb83da commit b99ff2a

1 file changed

Lines changed: 2 additions & 24 deletions

File tree

src/AngleSharp.Js/JsScriptingService.cs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,34 +76,12 @@ public Engine GetOrCreateJint(IDocument document) =>
7676
public async Task EvaluateScriptAsync(IResponse response, ScriptOptions options, CancellationToken cancel)
7777
{
7878
var encoding = options.Encoding ?? Encoding.UTF8;
79-
var context = options.Document.Context;
80-
var loop = context.GetService<IEventLoop>();
8179

8280
using (var reader = new StreamReader(response.Content, encoding, true))
8381
{
8482
var content = await reader.ReadToEndAsync().ConfigureAwait(false);
85-
86-
if (loop != null)
87-
{
88-
var tcs = new TaskCompletionSource<Boolean>();
89-
loop.Enqueue(_ =>
90-
{
91-
try
92-
{
93-
EvaluateScript(options.Document, content);
94-
tcs.SetResult(true);
95-
}
96-
catch (Exception ex)
97-
{
98-
tcs.SetException(ex);
99-
}
100-
}, TaskPriority.Critical);
101-
await tcs.Task.ConfigureAwait(false);
102-
}
103-
else
104-
{
105-
EvaluateScript(options.Document, content);
106-
}
83+
await options.EventLoop.EnqueueAsync(_ =>
84+
EvaluateScript(options.Document, content), TaskPriority.Critical).ConfigureAwait(false);
10785
}
10886
}
10987

0 commit comments

Comments
 (0)