diff --git a/com.chartboost.mediation/Runtime/Events/EventProcessor.cs b/com.chartboost.mediation/Runtime/Events/EventProcessor.cs index ef2ec2fa..f9b01e43 100644 --- a/com.chartboost.mediation/Runtime/Events/EventProcessor.cs +++ b/com.chartboost.mediation/Runtime/Events/EventProcessor.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using Chartboost.AdFormats.Banner; using Chartboost.Utilities; using UnityEditor; @@ -31,6 +32,7 @@ internal enum BannerAdEvents } private static SynchronizationContext _context; + private static TaskScheduler _unityScheduler; /// /// Called when an unexpected system error occurred. @@ -45,7 +47,42 @@ internal enum BannerAdEvents [InitializeOnLoadMethod] #endif [RuntimeInitializeOnLoadMethod] - private static void Initialize()=> _context ??= SynchronizationContext.Current; + private static void Initialize() + { + _context ??= SynchronizationContext.Current; + _unityScheduler ??= TaskScheduler.FromCurrentSynchronizationContext(); + } + + /// + /// Creates a continuation that executes asynchronously, on the Unity main thread, when the target completes. + /// + /// Target . + /// An action to run when the completes. + /// The type of the result produced by the . + /// A new continuation . + public static Task ContinueWithOnMainThread(this Task task, Action> continuation) + { + var ret = task.ContinueWith(continuation, CancellationToken.None, TaskContinuationOptions.None, _unityScheduler); + ret.AppendExceptionLogging(); + return ret; + } + + /// + /// Creates a continuation that executes asynchronously, on the Unity main thread, when the target completes. + /// + /// Target . + /// An action to run when the completes. + /// The type of the result produced by the . + /// A new continuation . + public static Task ContinueWithOnMainThread(this Task task, Action continuation) + { + var ret = task.ContinueWith(continuation, CancellationToken.None, TaskContinuationOptions.None, _unityScheduler); + ret.AppendExceptionLogging(); + return ret; + } + + private static void AppendExceptionLogging(this Task inputTask) + => inputTask.ContinueWith(faultedTask => Debug.LogException(faultedTask.Exception), TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously); public static void ProcessEventWithILRD(string dataString, ChartboostMediationILRDEvent ilrdEvent) { diff --git a/com.chartboost.mediation/Runtime/Utilities/AndroidConstants.cs b/com.chartboost.mediation/Runtime/Utilities/AndroidConstants.cs index 3e165d8a..78b48548 100644 --- a/com.chartboost.mediation/Runtime/Utilities/AndroidConstants.cs +++ b/com.chartboost.mediation/Runtime/Utilities/AndroidConstants.cs @@ -88,7 +88,7 @@ internal static class AndroidConstants internal const string PropertyAuctionId = "auction-id"; internal const string PropertyLineItemId = "line_item_id"; internal const string PropertyLineItemName = "line_item_name"; - internal const string PropertyPrice = "line_item_name"; + internal const string PropertyPrice = "price"; internal const string PropertyName = "name"; internal const string PropertyWidth = "width"; internal const string PropertyHeight = "height";