-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathAtom.NoWatch.cs
44 lines (38 loc) · 1.06 KB
/
Atom.NoWatch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
using UniMob.Core;
namespace UniMob
{
public static partial class Atom
{
/// <summary>
/// Creates a scope which blocks changes propagation. <br/>
/// <br/>
/// Must only be used in using statement.
/// </summary>
/// <example>
///
/// using (Atom.NoWatch)
/// {
/// // ...
/// }
///
/// </example>
public static IDisposable NoWatch => WatchScope.Enter();
private class WatchScope : IDisposable
{
private static readonly WatchScope Instance = new WatchScope();
private static readonly Stack<AtomBase> WatchStack = new Stack<AtomBase>();
public static IDisposable Enter()
{
WatchStack.Push(AtomBase.Stack);
AtomBase.Stack = null;
return Instance;
}
public void Dispose()
{
AtomBase.Stack = WatchStack.Pop();
}
}
}
}