Skip to content

Commit a51cc30

Browse files
campersauamaitland
authored andcommitted
Move FramePendingTaskRepository to its own file
1 parent 73131d3 commit a51cc30

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright © 2015 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
using System;
6+
using System.Collections.Concurrent;
7+
using System.Threading.Tasks;
8+
9+
namespace CefSharp.Internals
10+
{
11+
internal sealed class FramePendingTaskRepository<TResult> : IDisposable
12+
{
13+
public ConcurrentDictionary<long, TaskCompletionSource<TResult>> PendingTasks { get; } =
14+
new ConcurrentDictionary<long, TaskCompletionSource<TResult>>();
15+
public ConcurrentDictionary<long, TaskCompletionSource<TResult>> CallbackPendingTasks { get; } =
16+
new ConcurrentDictionary<long, TaskCompletionSource<TResult>>();
17+
18+
public void Dispose()
19+
{
20+
foreach (var tcs in PendingTasks.Values)
21+
{
22+
tcs.TrySetCanceled();
23+
}
24+
PendingTasks.Clear();
25+
26+
foreach (var tcs in CallbackPendingTasks.Values)
27+
{
28+
tcs.TrySetCanceled();
29+
}
30+
CallbackPendingTasks.Clear();
31+
}
32+
}
33+
}

CefSharp/Internals/PendingTaskRepository.cs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ namespace CefSharp.Internals
1919
/// <typeparam name="TResult">The type of the result produced by the tasks held.</typeparam>
2020
public sealed class PendingTaskRepository<TResult>
2121
{
22-
private readonly ConcurrentDictionary<string, FramePendingTaskRepository> framePendingTasks =
23-
new ConcurrentDictionary<string, FramePendingTaskRepository>();
22+
private readonly ConcurrentDictionary<string, FramePendingTaskRepository<TResult>> framePendingTasks =
23+
new ConcurrentDictionary<string, FramePendingTaskRepository<TResult>>();
2424
//should only be accessed by Interlocked.Increment
2525
private long lastId;
2626

@@ -39,7 +39,7 @@ public KeyValuePair<long, TaskCompletionSource<TResult>> CreatePendingTask(strin
3939
#if NETCOREAPP
4040
framePendingTasks.AddOrUpdate(
4141
frameId,
42-
(key, state) => { var value = new FramePendingTaskRepository(); value.PendingTasks.TryAdd(state.Key, state.Value); return value; },
42+
(key, state) => { var value = new FramePendingTaskRepository<TResult>(); value.PendingTasks.TryAdd(state.Key, state.Value); return value; },
4343
(key, value, state) => { value.PendingTasks.TryAdd(state.Key, state.Value); return value; },
4444
result
4545
);
@@ -74,7 +74,7 @@ public KeyValuePair<long, TaskCompletionSource<TResult>> CreateJavascriptCallbac
7474
#if NETCOREAPP
7575
framePendingTasks.AddOrUpdate(
7676
frameId,
77-
(key, state) => { var value = new FramePendingTaskRepository(); value.CallbackPendingTasks.TryAdd(state.Key, state.Value); return value; },
77+
(key, state) => { var value = new FramePendingTaskRepository<TResult>(); value.CallbackPendingTasks.TryAdd(state.Key, state.Value); return value; },
7878
(key, value, state) => { value.CallbackPendingTasks.TryAdd(state.Key, state.Value); return value; },
7979
result
8080
);
@@ -106,7 +106,7 @@ public KeyValuePair<long, TaskCompletionSource<TResult>> CreateJavascriptCallbac
106106
/// </returns>
107107
public TaskCompletionSource<TResult> RemovePendingTask(string frameId, long id)
108108
{
109-
FramePendingTaskRepository repository;
109+
FramePendingTaskRepository<TResult> repository;
110110
if (framePendingTasks.TryGetValue(frameId, out repository))
111111
{
112112
TaskCompletionSource<TResult> result;
@@ -131,7 +131,7 @@ public TaskCompletionSource<TResult> RemovePendingTask(string frameId, long id)
131131
/// </returns>
132132
public TaskCompletionSource<TResult> RemoveJavascriptCallbackPendingTask(string frameId, long id)
133133
{
134-
FramePendingTaskRepository repository;
134+
FramePendingTaskRepository<TResult> repository;
135135
if (framePendingTasks.TryGetValue(frameId, out repository))
136136
{
137137
TaskCompletionSource<TResult> result;
@@ -150,7 +150,7 @@ public TaskCompletionSource<TResult> RemoveJavascriptCallbackPendingTask(string
150150
/// <param name="frameId">The frame id.</param>
151151
public void CancelPendingTasks(string frameId)
152152
{
153-
FramePendingTaskRepository repository;
153+
FramePendingTaskRepository<TResult> repository;
154154
if (framePendingTasks.TryRemove(frameId, out repository))
155155
{
156156
repository.Dispose();
@@ -168,28 +168,5 @@ public void CancelPendingTasks()
168168
}
169169
framePendingTasks.Clear();
170170
}
171-
172-
private sealed class FramePendingTaskRepository : IDisposable
173-
{
174-
public ConcurrentDictionary<long, TaskCompletionSource<TResult>> PendingTasks { get; } =
175-
new ConcurrentDictionary<long, TaskCompletionSource<TResult>>();
176-
public ConcurrentDictionary<long, TaskCompletionSource<TResult>> CallbackPendingTasks { get; } =
177-
new ConcurrentDictionary<long, TaskCompletionSource<TResult>>();
178-
179-
public void Dispose()
180-
{
181-
foreach (var tcs in PendingTasks.Values)
182-
{
183-
tcs.TrySetCanceled();
184-
}
185-
PendingTasks.Clear();
186-
187-
foreach (var tcs in CallbackPendingTasks.Values)
188-
{
189-
tcs.TrySetCanceled();
190-
}
191-
CallbackPendingTasks.Clear();
192-
}
193-
}
194171
}
195172
}

0 commit comments

Comments
 (0)