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

Scheduler usage #236

Closed
adamski opened this issue Jul 31, 2024 · 2 comments
Closed

Scheduler usage #236

adamski opened this issue Jul 31, 2024 · 2 comments

Comments

@adamski
Copy link

adamski commented Jul 31, 2024

I'd like to make use of the scheduler so that I can check login status on a thread, and set up the realm once logged in on the main thread.

I'm using Scheduler::invoke on a scheduler created with Scheduler::make_default(). Is there something I'm missing?

            auto scheduler = realm::util::Scheduler::make_default();
            std::thread loginThread ([this, username, scheduler]()
                                     {
            try
            {
                std::future_status status;
                // TODO: Improve security with JWT based login
                std::string credentials = "{ \"username\": \"" + username + "\" }";

                std::cout << "Logging in..." << std::endl;
                auto userFuture = app->login (realm::App::credentials::function (credentials));
                std::cout << "Waiting for response" << std::endl;

                do
                {
                    switch (status = userFuture.wait_for (50ms); status)
                    {
                        case std::future_status::deferred:
                            std::cout << "deferred\n";
                            break;
                        case std::future_status::timeout:
                            std::cout << "timeout\n";
                            break;
                        case std::future_status::ready:
                            std::cout << "ready!\n";
                            break;
                    }
                } while (status != std::future_status::ready);

                user = userFuture.get();
                std::cout << "Logged in. User ID is " << user.identifier() << '\n';

                scheduler->invoke ([this]
                                   {
                                       setupSyncedRealm();
                                       setupSubscriptions();
                                       setupObservers();
                                   });
            }
            catch (const realm::app_error& e)
            {
                std::cout << "Error logging in: " << e.message() << std::endl;
                return;
            } });

            loginThread.detach();
Copy link

sync-by-unito bot commented Jul 31, 2024

➤ PM Bot commented:

Jira ticket: RCPP-87

@adamski adamski changed the title Use of the scheduler Scheduler usage Jul 31, 2024
@leemaguire
Copy link
Contributor

@adamski The scheduler is not intended to be used this way, its purpose is to perform change calculations for notifications and notify the callback when they are ready.

@adamski adamski closed this as completed Aug 2, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants