pub.flow:clearPipeline

I ve a very simple question regarding this public service. I read the manual and it was not clear:

I have 2 flow services Flow_Parent and Flow_Child.

Flow_Parent has 2 Input fields: A and B.

Flow_Child has 1 Input: B. The last instruction is pub.flow:clearPipeline.

If I call Flow_Child inside Flow_Parent, will I still have A and B in the pipeline after the Flow_Child invocation???

Of cource I ve done this already, and yes A and B were still on the pipeline of Flow_Parent. But Why??? What is the logic (it’s not explained on the manual). pub.flow:clearPipeline only works for local flow variables?

Thanks in advance,

F

Yes you will have both the variable in parent service. No variable at parent level will be removed from the pipeline from child services. If you don’t need the variable in the “Flow_Parent” use clearPipeline there. This make sense since if you call a child service for doing some small work and if it clear all parent service variablw will be a major issue. Or you need all parent service variable to put in exception list of child’s clearPipeline and which is not good.

Bibek

Ok, it was not clear on the manual: “Removes all fields from the pipeline. You may optionally specify fields that should not be cleared by this service.”

It should explain a bit more than this.

Every service gets a local “copy” of the pipeline. I say “copy”, because it is not really a copy, depending upon the type of data in the pipeline. Here’s how it works:

String variables that are not contained within a document are passed by value (you get a copy).

Documents (which are really object instances of the IData class) and other objects are passed by Reference (you get a reference “handle”).

Calling pub.flow:clearPipeline in a child service removes the strings in the local pipeline, but since they are copies, does not remove them from the parent pipeline. Documents and objects simply get dereferenced when clearPipeline is called (i.e. the ref count on the object is reduced by 1 - in general, an object will stay “alive” while it’s ref count is greater than 0 - indicating that some other object still has a handle on it and is probably using it).

There are other implications of this as well, that you need to understand:

  1. If you modify the value of a string variable in a child service into which it is passed, and then drop that variable in the child service, it will have absolutely no impact on the value of that variable in the parent service. (If you do not drop it, then the value in the parent will get overwritten when the child pipeline is merged with the parent pipeline upon completion of the child service).
  2. If you modify the value of a string variable contained within a document in a child service into which that document is passed, and then drop that variable in the child service, it WILL have already updated the value in the parent service since documents are objects and there is only a single “copy”.

Hope that explains it in a bit more detail…

2 Likes

Yes, your answer was most helpfull. :slight_smile:

Thanks