Yes this is how you can share non signal variables as well. However, if you
use a non-signal variable to share state, your state updates will not be
propagated across clients one the main function has executed.

If you persist state like in the example, you can load it and make it the
initial value of the shared signal after a restart, picking up where you
left off

On Mon 1 Feb, 2016, 1:44 PM Leonardo <[email protected]> wrote:

> Hi Shashi,
> this technique is applicable also for non-Signal variables, right?
>
> However, persistence hints for Signals are very interestings ...
>
> Thanks
>
> Leonardo
>
>
> Il 31/01/2016 19:11, Shashi Gowda ha scritto:
> > Hi Leonardo
> >
> > If you have a single Escher process serving multiple requests and you
> > want to share some state between them, my recommendation would be to put
> > the shared data in signal, which can optionally be persisted to disk/DB
> >
> > something like
> >
> > if !isdefined(:my_global_var) # this condition makes sure all your UIs
> > are referring to the same variable
> >      my_global_signal = Signal(Any, initial_value)
> >
> >      # you could also persist this to disk/DB for re-reading later, if
> > you have a function that can do that.
> >      Reactive.foreach(save_to_disk, my_global_signal)
> >
> >      # optionally you could save throttle(1.0, my_global_signal) to make
> > sure the state is saved at most once every second so as to not hit the
> > disk often
> > end
> >
> > function main(window)
> >     # ... use my_global_signal here, to get and put updates: every
> > client will be notified of updates...
> > end
> >
> >
> >
> > On Sun, Jan 31, 2016 at 5:47 PM, Leonardo <[email protected]
> > <mailto:[email protected]>> wrote:
> >
> >     Hi all,
> >     I want write an application with a Web UI (e.g. a chat) that has a
> >     local state (specific for each client) and global one (a state bind
> >     to web server).
> >     These requirements are useful for example to permit communications
> >     between different client (e.g. into a chat) and/or handle
> >     centralized resources (like a DB connection shared by all client and
> >     created once into web server).
> >
> >     How can I do that?
> >
> >     Many thanks in advance
> >
> >     Leonardo
> >
> >
>

Reply via email to