Delaying filename property assignment for file writers #2097
Replies: 1 comment
-
Hi @rachelmcassidy - I think your issue here is to do with subscription order with PropertyMappings, in some cases an externalized property can set an operator property before the input data is available. A common pattern to avoid this is to wrap the file writers in a SelectMany and use an async subject inside to subscribe to the relevant property data. Because the observable sequence for an async subject must terminate before it produces values, this ensures that the externalized property must 'wait' for the data before initialising the operator. A quick example below: In this example, a String defining the path name is pushed to an async subject (using Take to ensure the sequence terminates). KeyDown is used to create a new observable that initialises a CsvWriter. The Timer here is just an example data stream to write as Csv, the externalized FileName property depends on the async subject containing the path name - so every time a key is pressed (or any input event) the CsvWriter should be initialised with the latest path as the filename. |
Beta Was this translation helpful? Give feedback.
-
I would like to use fields from a GUI to define file paths for csv, matrix, and video writers, but only after a button is pressed. Most of my attempts to update the filename property result in the files being created as soon as the workflow starts, even though the upstream nodes don't emit notifications until the button press. I've attached a simplified workflow with a few different configurations:
Only (4) writes a file with the current path, and all others write to the path from the previous workflow run. Is there a better way to delay the filename assignment until the button is pressed? This issue has come up in a few scenarios, and SubscribeWhen isn't always ideal. I thought the InputMapping node would work, but the file is being created before the first property value is passed to the CsvWriter.
Thanks for any tips!
PropertyUpdating.bonsai.zip
Beta Was this translation helpful? Give feedback.
All reactions