Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public class CallbackThreadManager #1776

Merged
merged 1 commit into from
May 12, 2023

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented May 12, 2023

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 case setExternalUserId 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

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes
    • New CallbackThreadManager class

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

This new public API allows changing the default thread used to fire aync
events, observers, and callbacks for the rest of the OneSignal public
API.

This is intended for advanced use-case, motivated
mostly a need of 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.
@jkasten2 jkasten2 merged commit 36951ff into main May 12, 2023
1 of 2 checks passed
@jkasten2 jkasten2 deleted the feat/prefer_thread_for_callbacks branch May 12, 2023 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants