nezuo / lapis

A DataStore abstraction library for Roblox
https://nezuo.github.io/lapis/
MIT License
59 stars 10 forks source link

Throw error if beforeSave or beforeClose yield #63

Closed nezuo closed 2 months ago

nezuo commented 2 months ago

This fixes an edge case where one of the callbacks could yield right before or during game:BindToClose which means the save won't have started and AutoSave won't wait for the document to close.

This could be fixed without restricting yielding but there is another awkward API issue this fixes: For example, if beforeSave yields and :close is called during the yield, the close will throw an error since :close can't be called during the beforeSave callback. This could also technically be fixed by checking the coroutine.status of the beforeSave thread before throwing this error. However, if the :close didn't yield in its callbacks the close request would happen before the save and that would result in a save happening after the close which is not good.

We may find solutions to these edge cases but I feel that it's more correct to not allow yielding.