Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add IsQuitting boolean, Quitting event, and StopOnQuit helper #52

Merged
merged 7 commits into from
Oct 29, 2021

Conversation

GeBo1
Copy link
Contributor

@GeBo1 GeBo1 commented Oct 28, 2021

Add support to detect/react to application quitting.

Plugins with long waits can cause game/studio to hang when quitting. Replace things like:

yield return new WaitForSecondsRealtime(ConfigSetting.Value * 60);

with:

yield return new WaitForSecondsRealtime(ConfigSetting.Value * 60).StopOnQuit();
if (KoikatsuAPI.IsQuitting) yield break;

and/or:

KoikatsuAPI.Instance.Quitting += (s,e) => StopAllCoroutines();

@GeBo1 GeBo1 requested a review from ManlyMarco October 28, 2021 20:06
Copy link
Collaborator

@ManlyMarco ManlyMarco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the coroutines, the event itself seems fine.

Are you sure the coroutines reliably get a chance to run after quitting starts?

If some coroutine needs to handle game quitting then it can add the condition by itself, having extra classes for this seems like an overkill with how niche this is.

@GeBo1
Copy link
Contributor Author

GeBo1 commented Oct 28, 2021

I've done experiments and found that (at least in some cases) they continue running and the game waits for them to complete. I've updated most of my plugins to watch for quitting, but I'm pretty sure autosave is hanging studio shutdown with it's wait for X minutes (which is why I wanted to move this to someplace more common), so I figured something more generic rather than everyone writing similar code, but I can remove them.

The other option is to just not use the WaitFor at all and do something like this:

var timeout  = Time.time + delay;
while (Time.time < timeout)  
{
    yield return null;
    if (IsQuitting) yield break;
}

@GeBo1
Copy link
Contributor Author

GeBo1 commented Oct 29, 2021

Removed extra classes and added single StopOnQuit() extension method.

@GeBo1 GeBo1 changed the title add IsQuitting boolean, Quitting event, and ShutdownSafe helpers add IsQuitting boolean, Quitting event, and StopOnQuit helper Oct 29, 2021
src/Shared.Core/Utilities/CoroutineUtils.cs Outdated Show resolved Hide resolved
src/Shared.Core/KoikatuAPIBase.cs Outdated Show resolved Hide resolved
src/Shared.Core/KoikatuAPIBase.cs Outdated Show resolved Hide resolved
src/Shared.Core/KoikatuAPIBase.cs Outdated Show resolved Hide resolved
GeBo1 and others added 4 commits October 29, 2021 11:01
Co-authored-by: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com>
Co-authored-by: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com>
Co-authored-by: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com>
Co-authored-by: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com>
@ManlyMarco ManlyMarco merged commit d5a4842 into IllusionMods:master Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants