Helper class for running chains of actions on both the main thread and a background thread.
Especially useful for doing ui that also needs networking. Think of it like a JS-like promise chain except with more C++.
bool success = SomeLongNetworkOperation();
return success;
})
bool success = var.value<bool>();
UpdateUI(success);
})
progress(0, 0);
progress(1, 1);
})
->
then(SomeOtherFunctionThatReturnsABackgroundThread())
serially
try
{
std::rethrow_exception(exc);
}
catch (std::exception e)
{
}
})
...
})
if (success)
{
ReportSuccess();
}
})
...
})
BackgroundThread * thenBackgroundWithProgress(QWidget *parent, const QString &title, const QString &text, const QString &cancel, Func &&func)
Add a function to run on a background thread, with a progress dialog that blocks the main thread whil...
Definition: progresstask.h:554
BackgroundThread * thenBackground(Func &&func)
Add a function to run on a background thread.
Definition: progresstask.h:526
std::function< bool(size_t, size_t)> ProgressFunction
Definition: progresstask.h:274
BackgroundThread * then(BackgroundThread *other)
Add another BackgroundThread's functions to the end of this one's.
Definition: progresstask.h:499
BackgroundThread * catchBackground(CatchFunction func)
Add a function to run on a background thread in the event an exception is thrown.
Definition: progresstask.h:615
BackgroundThread * catchMainThread(CatchFunction func)
Add a function to run on the main thread in the event an exception is thrown.
Definition: progresstask.h:626
BackgroundThread * finallyMainThread(FinallyFunction func)
Add a function to run on the main thread after all other functions, even if something threw.
Definition: progresstask.h:648
BackgroundThread * finallyBackground(FinallyFunction func)
Add a function to run on a background thread after all other functions, even if something threw.
Definition: progresstask.h:637
void start(QVariant init=QVariant())
Start the thread and run all its functions in sequence.
Definition: progresstask.h:446
static BackgroundThread * create(QObject *owner=nullptr)
Create a new background thread (but don't start it)
Definition: progresstask.h:436
BackgroundThread * thenMainThread(Func &&func)
Add a function to run on the main thread.
Definition: progresstask.h:538
void setText(const QString &text)
Set the text label on the progress dialog.
Wrapper around QThread and ProgressDialog that runs a task in the background, providing updates to th...
Definition: progresstask.h:106
std::function< bool(size_t, size_t)> SplitProgress(std::function< bool(size_t, size_t)> originalFn, size_t subpart, size_t subpartCount)
Split a single progress function into equally sized subparts.
Definition: binaryninjaapi.cpp:386