Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/AngleSharp.Js/Dom/MessageChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,27 @@ public static void Enqueue(IDocument document, Action action)

if (loop != null)
{
loop.Enqueue(action, TaskPriority.Normal);
loop.Enqueue(_ => Execute(document, action), TaskPriority.Normal);
return;
}

Queues.GetValue(document, static _ => new TaskQueue()).Enqueue(document, action);
}

private static void Execute(IDocument document, Action action)
{
var scripting = document.Context?.GetService<JsScriptingService>();

if (scripting != null)
{
scripting.GetOrCreateInstance(document).RunTask(action);
}
else
{
action();
}
}

private sealed class TaskQueue
{
private readonly Queue<Action> _actions = new Queue<Action>();
Expand Down Expand Up @@ -620,16 +634,7 @@ private void Run(IDocument document)

try
{
var scripting = document.Context?.GetService<JsScriptingService>();

if (scripting != null)
{
scripting.GetOrCreateInstance(document).RunTask(action);
}
else
{
action();
}
Execute(document, action);
}
catch (Exception error)
{
Expand Down
Loading