1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 01:53:01 +08:00

Add RealmContextFactory.Write helper method

This commit is contained in:
Dean Herbert 2022-01-21 17:08:02 +09:00
parent a59105635e
commit da0a803e6c

View File

@ -204,6 +204,24 @@ namespace osu.Game.Database
}
}
/// <summary>
/// Write changes to realm.
/// </summary>
/// <remarks>
/// Handles correct context management and transaction committing automatically.
/// </remarks>
/// <param name="action">The work to run.</param>
public void Write(Action<Realm> action)
{
if (ThreadSafety.IsUpdateThread)
Context.Write(action);
else
{
using (var realm = createContext())
realm.Write(action);
}
}
private Realm createContext()
{
if (isDisposed)