Add public class CallbackThreadManager #1776
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
New public API allows changing the default thread used to fire async events, observers, and callbacks for the rest of the OneSignal public API.
Details
Motivation
This is intended for advanced use-cased, motivated mostly by a need from the OneSignal Unity wrapper SDK. Specifically to avoid cases where Unity may cause the main UI thread to wait on a background thread when calling back into Unity. Given how the binding between C# and Java works here, there is no way for the C# code to switch threads itself, so this API has to be available to do so.
Scope
By default, this PR has no effect, however if
CallbackThreadManager.preference = UseThread.Background
is called this will fire click events (IAMs and Notifications), Observers, and the special casesetExternalUserId
callback (was special cased before this PR) to fire a on a new background thread.OneSignal-Unity-SDK
There will be a follow up PR to also utilize this in the
OneSignal-Unity-SDK
.Testing
Unit testing
None
Manual testing
Ensured setExternalUserId continued firing on the main UI thread, and also it fires on the background thread after chaing the preference.
Affected code checklist
CallbackThreadManager
classChecklist
Overview
Testing
Final pass
This change is