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:
parent
a59105635e
commit
da0a803e6c
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user