Example #1
0
        public void ReentrancyPriorityAdviceTest()
        {
            using var lifetimeDefinition = new LifetimeDefinition();
            var lifetime = lifetimeDefinition.Lifetime;

            var priorityAdvice = 0;
            var advice1        = 0;
            var advice2        = 0;

            var signal    = new Signal <Unit>();
            var lifetimes = new SequentialLifetimes(TestLifetime);

            signal.Advise(lifetime, _ =>
            {
                advice1++;
                using (Signal.PriorityAdviseCookie.Create())
                {
                    signal.Advise(lifetimes.Next(), _ => priorityAdvice++);
                }
            });

            signal.Advise(lifetime, _ => advice2++);

            for (int i = 0; i < 1000; i++)
            {
                signal.Fire();

                Assert.AreEqual(i + 1, advice1);
                Assert.AreEqual(i + 1, advice2);
                Assert.AreEqual(i, priorityAdvice);
            }
        }
Example #2
0
        public void TestSignalStress()
        {
            var sig = new Signal <bool>();

            using (var run = new LifetimeDefinition())
            {
                var lt       = run.Lifetime;
                var fireTask = Task.Factory.StartNew(() =>
                {
                    while (lt.IsAlive)
                    {
                        sig.Fire(true);
                    }
                }, lt);

                Parallel.For(0, 100000, i =>
                {
                    using (var ld = new LifetimeDefinition())
                        sig.Advise(ld.Lifetime, x => { });
                });

                run.Terminate();
                fireTask.Wait(TimeSpan.FromSeconds(1));
                Assert.AreEqual(TaskStatus.RanToCompletion, fireTask.Status);
            }
        }
Example #3
0
        public RiderFlowSceneToolbarRoot()
        {
            SetRootStyleProperties();
            var startupLabel = new Label("Initializing...");

            Add(startupLabel);
            ContainerReadyRequirement.Instance.IsReady.WhenTrue(myDefinition.Lifetime, (b) =>
            {
                Remove(startupLabel);
                myRiderFlowToolbarElements = new List <VisualElement>()
                {
                    ComponentContainer.GetComponent <SceneSearchPopupTool>().MakeVisualElement(myDefinition.Lifetime),
                    ComponentContainer.GetComponent <CameraPresetCreationTool>().MakeVisualElement(),
                    ComponentContainer.GetComponent <CameraPresetExplorerTool>().MakeVisualElement(),
                    ComponentContainer.GetComponent <BookmarkExplorerTool>().MakeVisualElement(),
                };
                foreach (var toolbarElement in myRiderFlowToolbarElements)
                {
                    Add(toolbarElement);
                }
                RegisterCallback <GeometryChangedEvent>(OnGeometryChanged);
                myParentSet.Advise(myDefinition.Lifetime, SetUpChildElements);
                mySceneOccurrenceExplorerTool = ComponentContainer.GetComponent <SceneOccurrenceExplorerTool>();
                mySceneOccurrenceExplorerTool.Session.Advise(myDefinition.Lifetime, session =>
                {
                    if (!myShowingFindUsages)
                    {
                        AddFindUsages();
                    }
                });

                RegisterCallback <DetachFromPanelEvent>(OnDestroy);
            });
        }
Example #4
0
File: RdSignal.cs Project: yvvan/rd
        public void Advise(Lifetime lifetime, Action <T> handler)
        {
            if (IsBound)
            {
                AssertThreading();
            }

            mySignal.Advise(lifetime, handler);
        }