[SOLVED] Shutting down observables

i fighting with observables a little.
I create an instrument and then a sample.
I connect notifiers /I could handle it/ but how do I disconnect it all when I close the tool ?
Checking for tool.visible in tool.app_idle_observable ?
if tool is not visible then remove notifiers ?

which way is the right one ?

That sounds about right, to my recollection.

You can create a “global” table (or even better some class, if you wanna go that route) where you store used observables and their functions. Then it’s easy to just iterate and unobserve whatever has been added without keeping track of stuff manually.

it’s still not a little clear to me how the tool actually behaves.
the first start is clear, but after the subsequent “end” so the tool window is not visible, it seems to me that the tool is just moved to the background but still running.
After the subsequent call from the menu, the start-up procedure is the same as the first time or different. it seems to me that its global variables still contain values when hidden.

Enabled tools are always running. (The GUI is not the tool. Lots of tools have no GUI.)

i want use something like you in this post

seems to be very usefull for bunch of observers

Ah. That one can be used if you just want to make a :bang() to run several functions at once. Maybe not quite the same.

But if you find yourself using a lot of observables/functions that you know you want to easily destroy at once (at gui close), it’s not a bad idea to just store them in a global table. tbl[1] = { obs = theobservable, func = regged_function }. Then it’s easy to destroy them all at once with a table iteration. (PS. don’t forget removing the destroyed element from this table)

In larger projects, I like being able to keep track of used observables anyway, with some simple rprint ‘debugging’.

thanks for your patience. I’ll try it

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.