private void Awake() { if (instance == null) { instance = this; } }
public static async Task <T> QueueTick <T>(Func <T> action) { var refHolder = new RefHolder <T>(); await QueueTick(() => { refHolder.Value = action(); }); return(refHolder.Value); }
public void StandardTest() { using (var session = Domain.OpenSession()) using (var tx = session.OpenTransaction()) { var book = new Book() { Title = "Book" }; var bookRef = new RefHolder <Book>(); bookRef.Ref = book; book.BookRef = bookRef; Assert.AreEqual(book, book.BookRef.Ref); } }
public void BasicTest() { var holder = new RefHolder(); var count = TestRunnerInfo.IsBuildAgent() ? 100 : 1000; var objects = Enumerable.Range(0, count).Select(i => i.ToString()).ToArray(); var holds = new HashSet <IDisposable>(); foreach (var o in objects) { holds.Add(holder.Hold(o)); } holder.IsEmpty.Should().BeFalse(); // HashSet randomizes the order of disposal foreach (var hold in holds) { hold.Dispose(); } holder.IsEmpty.Should().BeTrue(); }