iemon

Iemon (伊右衛門)

Awesome shared object in multiple processes for Crystal

Abstract

⭐️ This will work! ⭐️

my_object = MyObj.new(x: 1)

fork do
  my_object.x = 2
end

sleep 0.1

puts my_object.x
#=> 2

Installation

Add this to your application's shard.yml:

dependencies:
  iemon:
    github: tbrand/iemon

Usage

require "iemon"

Define your object which inherits Iemon::Object.

Iemon manages shared properties. You can define it by using assigns method.

class MyObj < Iemon::Object
  assigns(x: Int32)
end

Then x of MyObj will be shared between multiple processes.

So below code will work correctly.

my_obj = MyObj.new(x: 1)

fork do
  my_obj.x = 2
end

sleep 0.1 # wait a little for a forked process

puts my_obj.x
#=> 2

Call Iemon::Object#clean once if you don't need to share the properties of the object anymore.

Otherwise the shared memory remains even if the execution is finished.

my_obj.clean

If you forget to do that, you can clean all of them by

crystal lib/iemon/tools/clean.cr

Development

The project is still under the work in progress.

Any contributions are welcome! 🎉

Contributing

  1. Fork it (https://github.com/tbrand/iemon/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • tbrand Taichiro Suzuki - creator, maintainer
Repository

iemon

Owner
Statistic
  • 18
  • 0
  • 0
  • 0
  • 0
  • about 6 years ago
  • July 6, 2018
License

MIT License

Links
Synced at

Thu, 21 Nov 2024 04:51:34 GMT

Languages