multithreading - How to handle multiple threads, single outcome in a functional way? -


this not 'pure' functional question involves side-effects. have function may take 10 seconds, complete. function generates data in database (for example). if run twice @ same time create duplicate data. lets function can triggered clicking button in browser. if 2 people click within seconds of each other function can running twice concurrently.

in java , similar systems use synchronise on semaphore. in node or django can take advantage of single threading drop parallel runs.

running = false  def long_running_process():   global running    # run once   if running: return    try:     running = true     .... go ...   finally:     running = false 

the requirement in python global reference clear hint function requires state - , imperative nature.

so, questions.

  1. how 'pure' functional programs demand immutability handle problem?
  2. and how implement in python (for example)?
  3. is best option use reactive python library?

i know haskell people tell me create state monad, how clojure or elixir or ... handle it?


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -