Esempio n. 1
0
        private void Update()
        {
            if (!FlowTaskQueue.Any())
            {
                return;
            }

            while (UnderTaskLimit())
            {
                var taskFound = FlowTaskQueue.TryDequeue(out var nextTask);
                if (!taskFound)
                {
                    break;
                }

                var flowType     = nextTask.Flow;
                var multiplicity = nextTask.Multiplicity;
                var permanence   = nextTask.Permanence;
                var level        = nextTask.ExecutionLevel;
                var data         = nextTask.DataToProcess;
                var instance     = FlowCache.Request(flowType, multiplicity, permanence);

                CreateFlowTask(instance, () =>
                {
                    //Since the Daemon is the creator of this instance, create a callback to dynamically handle the result of the flow
                    void Callback(IFlowResult result) => DaemonFlowEndpoint(result, level + 1);

                    //Invoke!
                    instance.Process(data, (Action <IFlowResult>)Callback);
                });
            }
        }
Esempio n. 2
0
        public Daemon(int taskLimit, Action <TReturn> callback)
        {
            ResolverCache = new ResolverCache();
            FlowCache     = new FlowCache(ResolverCache);
            FlowTaskQueue = new SimplePriorityQueue <FlowTask, int>();
            ActiveFlows   = new Dictionary <Guid, IFlow>();
            Callback      = callback;

            if (taskLimit < 2)
            {
                taskLimit = 2;
            }
            TaskLimit = taskLimit;
        }