When calling Stop() there may still be be Jobs whose Goroutines have been created but were never scheduled. It is therefore impossible to wait for all Jobs to complete, because some may not yet be running, making it impossible to track them.
The right place for adding to a sync.WaitGroup would be in Cron:run() right before go c.runWithRecovery(e.Job). You could then add a new Cron:Wait() function for waiting for jobs to finish after calling Stop().
When calling
Stop()there may still be be Jobs whose Goroutines have been created but were never scheduled. It is therefore impossible to wait for all Jobs to complete, because some may not yet be running, making it impossible to track them.The right place for adding to a
sync.WaitGroupwould be inCron:run()right beforego c.runWithRecovery(e.Job). You could then add a newCron:Wait()function for waiting for jobs to finish after callingStop().