Sonjli 6 Posted May 10, 2019 Hi, simple question: how can I run a pipeline more than one time in the same method\procedure\function? I do like this ... MyPipeline := Parallel .Pipeline .stage(myStage1) .stage(myStage2); ... procedure MyProcedure; begin // First run MyPipeline.Run; MyPipeline.input.Add('ONE'); aValue := MyPipeline.Output.Next; // I tries also this... without success MyPipeline.Cancel; MyPipeline.WaitFor(INFINITE); // I do some stuff in the middle // First run MyPipeline.Run; // Here I receive "Pipeline is already running", but I don't think so... :( MyPipeline.input.Add('TWO'); aValue := MyPipeline.Output.Next; ... end; I am not finding any info in the docs. In the sources of IOmniPipeline I see a "opCountStopped" semaphore that is checked "Assigned" in the first run... but I really don't understand why this limits one instance of a IOmniPipeline to be run only one time in the same method. Thanks again Eddy Share this post Link to post
Primož Gabrijelčič 223 Posted May 10, 2019 Pipelines are not restartable by design. You create a pipeline, run it until you don't need it anymore, then tear it down. What problem are you trying to solve, anyway? Share this post Link to post
Sonjli 6 Posted May 13, 2019 Hi, sorry for late reading. I am trying to build a kind of a "protocol runner". I need an object which can accept different "actions" and then it can be run in loop to repeat the protocol. Example: Name: "Protocol 1: download a file with locks" 1. Wait until "the other" lock file disappear 2. Put "my" lock file in that folder 3. Download the main file 4. process the main file 5. Delete "my" lock file 7. Wait 5 seconds 8. Restart from 1 The entire loop must be run in a separate non-blocking thread. But every loop must be serialized. I thought that pipeline could be the answer, but I can't run it several times in that loop. I may use a state machine (https://github.com/malcolmgroves/TStateMachine) but I need to build several protocols changing one or more "actions" at runtime... I don't know if this is the right choice. Is my idea clear enough? I hope so... 🙂 Thanks Share this post Link to post
Primož Gabrijelčič 223 Posted May 13, 2019 If I understand correctly, this has nothing to do with a pipeline. a) You "create a protocol" (whatever that means) b) You submit that protocol to a background thread to execute it and c) you repeat step b. And you can do all that with different protocols. As one protocol is a normal serial process, it has nothing to do with threading. Just implement "protocol runner" as a state machine. Then create a Background Worker abstraction and submit it work items. One work item = one "protocol runnner". 1 Share this post Link to post