package

github.com/tbrand/iemon

0.0.1 / published Sep 5, 2018 / repository

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

API

  • Bool

    Override primitive types so that they can respond to detach and #clean.

  • Char

    Override primitive types so that they can respond to detach and #clean.

  • Float32

    Override primitive types so that they can respond to detach and #clean.

  • Float64

    Override primitive types so that they can respond to detach and #clean.

  • Iemon
  • Int128

    Override primitive types so that they can respond to detach and #clean.

  • Int16

    Override primitive types so that they can respond to detach and #clean.

  • Int32

    Override primitive types so that they can respond to detach and #clean.

  • Int64

    Override primitive types so that they can respond to detach and #clean.

  • Int8

    Override primitive types so that they can respond to detach and #clean.

  • String

    A String represents an immutable sequence of UTF-8 characters.

  • Symbol

    Override primitive types so that they can respond to detach and #clean.

  • UInt128

    Override primitive types so that they can respond to detach and #clean.

  • UInt16

    Override primitive types so that they can respond to detach and #clean.

  • UInt32

    Override primitive types so that they can respond to detach and #clean.

  • UInt64

    Override primitive types so that they can respond to detach and #clean.

  • UInt8

    Override primitive types so that they can respond to detach and #clean.