Skip to content

quezacoatl/probject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

A lightweight actor-based concurrent object framework with each object running in it's own process.

How does it work?

When a new object is created, it will fork and open up two UNIX sockets, one for requests and one for responses. Each method invocation on the actor is asynchronous, but one can optionally wait for the method to return by reading from the response channel, using a future.

To do asyncrhonous invocations, use .async or .tell

probject.async.my_method # => nil

To do asyncrhonous invocations that return a future, use .future or .ask

probject.future.my_method # => Probject::Future

To do syncrhonous invocations, just call the method as you normally would

probject.my_method # => whatever my_method returns

Example

This example is not very practical, but it illustrates how Probject can be used.

require 'net/http'
require 'probject'

class GoogleRequester < Probject::Actor

  def do_request
    @response = Net::HTTP.get('www.google.com', '/')
  end

  def response_length
    @response.length
  end
end

probjects = []

1.upto 5 do |i|
  probjects[i] = GoogleRequester.new

  probjects[i].async.do_request
end

1.upto 5 do |i|
  # do a synchronous request - will block until all previous requests have been handled
  puts probjects[i].response_length
  # could also be written as probjects[i].future.response_length.get
end

Install

$ gem install probject

Platform support

This gem is written for MRI, where forking is the best way of implementing concurrenent applications, and real threading is not supported. If you use Rubinius or JRuby I would propose looking in to Celluloid.

Windows does not work for two reasons - no UNIX sockets and no forking implemented in Ruby.

supported

  • MRI (1.9+) on *NIX

License

Released under the MIT License. See LICENSE.txt.

About

A lightweight actor-based concurrent object framework with each object running in it's own process

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages