how do you detect if an operation is done?

say you want to create a progressbar that will work accordingly with the progress of the operation

operation for ex can be - saving a file, performing an iteration ...