Uploaded image for project: 'Realm C++ SDK'
  1. Realm C++ SDK
  2. RCPP-87

Scheduler usage

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

XMLWordPrintableJSON

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      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();
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Archiver:
            marc.greenfield@mongodb.com Marc Greenfield

              Created:
              Updated:
              Archived: