Пример #1
0
        private void FulfillChildWaits()
        {
            List <LuaThread> threads;
            var parent = _parent;

            if (parent == null || !parent._waitForChildList.TryGetValue(_name, out threads))
            {
                return;
            }
            foreach (var t in threads)
            {
                ScriptService.ResumeThread(t);
            }
            threads.Clear();
            parent._waitForChildList.Remove(_name);
        }
Пример #2
0
        public double wait()
        {
            var thread = (LuaThread)LuaThread.running().Values[0];
            var sw     = Stopwatch.StartNew();

            Action callback = null;

            callback = () =>
            {
                ScriptService.ResumeThread(thread);
                Disconnect(callback);
            };

            Connect(callback);
            ScriptService.YieldThread();
            return(sw.Elapsed.TotalSeconds);
        }
Пример #3
0
        public Instance WaitForChild(string name, double?timeout = null)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Name parameter cannot be empty.");
            }

            foreach (var c in Children)
            {
                if (c.Name == name)
                {
                    return(c);
                }
            }

            var thread = (LuaThread)LuaThread.running().Values[0];

            lock (Locker)
            {
                List <LuaThread> threads;
                if (_waitForChildList.TryGetValue(name, out threads))
                {
                    threads.Add(thread);
                }
                else
                {
                    _waitForChildList.Add(name, new List <LuaThread>(new[] { thread }));
                }
            }

            Timer timer       = null;
            var   timerAction = new TimerCallback(obj =>
            {
                ScriptService.ResumeThread(thread);
                timer?.Dispose();
            });

            timer = timeout == null ? new Timer(timerAction) : new Timer(timerAction, null, (int)(timeout * 1000), -1);

            ScriptService.YieldThread();

            return(FindFirstChild(name));
        }