iemon

Awesome shared object in multiple processes
0.0.1 Latest release released
tbrand/iemon
18
Taichiro Suzuki

Iemon (伊右衛門)

Awesome shared object in multiple processes for Crystal

Abstract

:star: This will work! :star:

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! :tada:

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
iemon:
  github: tbrand/iemon
  version: ~> 0.0.1
License MIT
Crystal 0.25.0

Authors

Dependencies 0

Development Dependencies 0

Dependents 0

Last synced .
search fire star recently