Skip to content

Commit e09f12c

Browse files
committed
add coroutine exception handler
1 parent 307de9d commit e09f12c

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Analytics-CSharp/Analytics-CSharp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
<Folder Include="Segment\Analytics\Utilities\" />
3333
</ItemGroup>
3434
<ItemGroup>
35-
<PackageReference Include="Coroutine.NET" Version="0.5.0" />
35+
<PackageReference Include="Coroutine.NET" Version="1.0.0" />
3636
<PackageReference Include="Serialization.NET" Version="0.1.0" />
37-
<PackageReference Include="Sovran.NET" Version="0.4.0" />
37+
<PackageReference Include="Sovran.NET" Version="1.0.0" />
3838
</ItemGroup>
3939
<ItemGroup>
4040
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">

Analytics-CSharp/Segment/Analytics/Analytics.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public partial class Analytics : ISubscriber
3333
public Analytics(Configuration configuration)
3434
{
3535
this.configuration = configuration;
36-
analyticsScope = new Scope();
36+
analyticsScope = new Scope(configuration.exceptionHandler);
3737
if (configuration.userSynchronizeDispatcher)
3838
{
3939
IDispatcher dispatcher = new SynchronizeDispatcher();
@@ -48,7 +48,7 @@ public Analytics(Configuration configuration)
4848
analyticsDispatcher = new Dispatcher(new LimitedConcurrencyLevelTaskScheduler(Environment.ProcessorCount));
4949
}
5050

51-
store = new Store(configuration.userSynchronizeDispatcher);
51+
store = new Store(configuration.userSynchronizeDispatcher, configuration.exceptionHandler);
5252
storage = new Storage(store, configuration.writeKey, configuration.persistentDataPath, fileIODispatcher);
5353
timeline = new Timeline();
5454

Analytics-CSharp/Segment/Analytics/Configuration.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
using Segment.Concurrent;
3+
24
namespace Segment.Analytics
35
{
46
public class Configuration
@@ -21,6 +23,8 @@ public class Configuration
2123

2224
public bool userSynchronizeDispatcher { get; }
2325

26+
public ICoroutineExceptionHandler exceptionHandler { get; }
27+
2428
/// <summary>
2529
/// Configuration that analytics can use
2630
/// </summary>
@@ -38,7 +42,8 @@ public class Configuration
3842
/// <param name="autoAddSegmentDestination">automatically add SegmentDestination plugin, defaults to <c>true</c></param>
3943
/// <param name="userSynchronizeDispatcher">forcing everything to run synchronously, used for unit tests </param>
4044
/// <param name="apiHost">set a default apiHost to which Segment sends events, defaults to <c>api.segment.io/v1</c></param>
41-
/// <param name="cdnHost">et a default cdnHost to which Segment fetches settings, defaults to <c>cdn-settings.segment.com/v1</c></param>
45+
/// <param name="cdnHost">set a default cdnHost to which Segment fetches settings, defaults to <c>cdn-settings.segment.com/v1</c></param>
46+
/// <param name="exceptionHandler">set a an exception handler to handle errors happened in async methods within the analytics scope</param>
4247
public Configuration(string writeKey,
4348
string persistentDataPath,
4449
int flushAt = 20,
@@ -47,7 +52,8 @@ public Configuration(string writeKey,
4752
bool autoAddSegmentDestination = true,
4853
bool userSynchronizeDispatcher = false,
4954
string apiHost = null,
50-
string cdnHost = null)
55+
string cdnHost = null,
56+
ICoroutineExceptionHandler exceptionHandler = null)
5157
{
5258
this.writeKey = writeKey;
5359
this.persistentDataPath = persistentDataPath;
@@ -58,6 +64,7 @@ public Configuration(string writeKey,
5864
this.userSynchronizeDispatcher = userSynchronizeDispatcher;
5965
this.apiHost = apiHost;
6066
this.cdnHost = cdnHost;
67+
this.exceptionHandler = exceptionHandler;
6168
}
6269
}
6370

0 commit comments

Comments
 (0)