mirror of https://github.com/ppy/osu
Add `RealmContextFactory.Write` helper method
This commit is contained in:
parent
a59105635e
commit
da0a803e6c
|
@ -204,6 +204,24 @@ public void Run(Action<Realm> action)
|
|||
}
|
||||
}
|
||||
|
||||
/// <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