GithubHelp home page GithubHelp logo

affect's People

Contributors

immortalin avatar noteflakes avatar timhabermaas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

affect's Issues

Thread-safety?

Affect.capture doesn't seem thread-safe because it mutates the current context (@@current) class variable and Affect is shared across threads.

For example:

t1 = Thread.new  {
  Affect.capture(log: -> (message) { puts "logging 1: #{message}" }) do
    Affect.perform(:log, "foo")
  end
}

t2 = Thread.new {
  Affect.capture(log: -> (message) { puts "logging 2: #{message}" }) do
    Affect.perform(:log, "bar")
  end
}
t1.join
t2.join

might end up printing "logging 2: foo\nlogging 2: bar\n" instead of "logging 1: foo\nlogging 2: bar\n".

This specific issue can be fixed by using Thread.current[:current_ctx] to attach the current context to the current thread (do you want me to open a PR?). However: I think this will lead to other issues when using Threads in user-land [1].

So I looked into using the fiber implementation which doesn't mutate global state, so the above code works fine. I believe it has the same problem when using Thread.new around perform as the Thread.current solution, though. Fibers don't seem to play nicely with threads.

Do you have any experience using your affect library in a multi-threaded environment? Maybe it's best to simply ban threads from user-land?

[1] The part of a code base which only cares about perform, not about how to handle the effects.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.