37 wxTheApp->CallAfter( std::move( aFn ) );
44 [aWatch, fn = std::move( aFn )]()
61 std::function<
void(
const wxString& )> aShow ) :
74 std::lock_guard<std::mutex> lock(
m_mutex );
112 const std::function<
void()>& aDone )
118 std::weak_ptr<bool> alive =
m_alive;
124 auto completion = std::make_shared<std::function<void()>>( aDone );
128 bool started =
false;
133 [
this, alive, token, aWork, completion]()
138 [
this, alive, completion]()
142 std::function<void()> done = std::move( *completion );
184 std::function<
void()> aDone )
186 REQUEST request{ std::move( aSession ), std::move( aWork ), std::move( aDone ), ++
m_generation };
195 start( std::move( request ) );
209 auto error = std::make_shared<std::exception_ptr>();
211 auto done = [
this, error, generation = aRequest.
generation, complete = std::move( aRequest.
done )]()
233 std::rethrow_exception( *error );
235 catch(
const std::exception& e )
237 wxLogError(
_(
"Could not read the Git repository: %s" ), wxString::FromUTF8( e.what() ) );
241 wxLogError(
_(
"Could not read the Git repository." ) );
246 bool started =
false;
252 [error, session = std::move( aRequest.
session ),
257 if( !session || aCancel->load() || session->IsShuttingDown() )
260 std::unique_lock<std::mutex> lock = session->LockAction();
262 if( aCancel->load() || session->IsShuttingDown() || !session->GetRepo() )
265 KIGIT_COMMON::OPERATION_GUARD operation( session.get(), aCancel );
267 if( !aCancel->load() && work )
274 *error = std::current_exception();
281 *error = std::current_exception();
KIGIT_ORPHAN_REGISTRY & OrphanRegistry()
Return the process-wide orphan thread registry owned by this backend.
The project's git session.
std::shared_ptr< std::atomic< bool > > CANCEL_TOKEN
One token per operation.
static CANCEL_TOKEN NewCancelToken()
bool Register(const std::string &aLabel, F &&aWork)
Spawn a tracked orphan thread running aWork.
KIGIT_TRANSFER m_transfer
void Cancel()
Suppress the running completion and discard pending work. Does not wait for a read.
std::optional< REQUEST > m_pending
void start(REQUEST aRequest)
void Run(std::shared_ptr< KIGIT_COMMON > aSession, std::function< void(KIGIT_COMMON &)> aWork, std::function< void()> aDone)
Run aWork under the session's action lock on a worker, then aDone on the UI thread.
std::function< void(const wxString &)> m_show
std::weak_ptr< bool > m_alive
KIGIT_STATUS_REPORTER(const std::weak_ptr< bool > &aAlive, std::function< void(const wxString &)> aShow)
KIGIT_COMMON::CANCEL_TOKEN m_cancel
The token of the transfer started last.
std::shared_ptr< std::function< void()> > m_completion
Created and cleared on the UI thread.
std::shared_ptr< bool > m_alive
Dropped when this object goes, so a transfer that outlives it completes into nothing.
void Cancel()
Ask the running transfer to stop. It finishes on its own time.
bool Start(const std::string &aLabel, const std::function< void(const KIGIT_COMMON::CANCEL_TOKEN &)> &aWork, const std::function< void()> &aDone)
Run aWork on a background thread, then aDone on the UI thread.
PROGRESS_REPORTER_BASE(int aNumPhases)
GIT_BACKEND * GetGitBackend()
bool StartTransfer(const std::string &aLabel, std::function< void()> aWork)
Run aWork on a thread the orphan registry owns.
void CallIfAlive(const std::weak_ptr< bool > &aWatch, std::function< void()> aFn)
As CallOnUi, for work that touches the window that started the transfer.
void CallOnUi(std::function< void()> aFn)
Run aFn on the UI thread.
std::function< void()> done
std::function< void(KIGIT_COMMON &)> work
std::shared_ptr< KIGIT_COMMON > session