Methods
From Reia
Contents |
Calling methods
Reia uses the . operator to invoke a method on an object.
obj = Foo() obj.meth(arg1, arg2, arg3)
Blocks can be passed to methods as well:
obj.meth(arg1, arg2) { |blockarg1, blockarg2| ... }
Asynchronous calls
- Sorry, async calls are presently unimplemented
Reia allows methods to be invoked asynchronously. This means the caller ignores the return value of the method and proceeds about its business. When the remote object finally completes the methods, the return value, if any, is discarded.
Reia uses the <- operator to perform an asynchronous method invocation.
>> obj = Foo()
=> #<Object>
>> obj<-bar("baz!")
=> nil
Handling calls asynchronously
- Sorry, async method dispatch and reply/noreply are presently unimplemented
Reia objects can expose a normal method call to the caller while handling it asynchronously on the backend.
Reia supports the reply and noreply keywords to control what is sent back to the caller.
def foo reply 42
The reply keyword sends the given value back to the caller as the method's response. The noreply keyword doesn't send a method response at all. By default, a method will reply with the last expression evaluated.
The noreply keyword can be used in conjunction with the caller keyword to allow a reply to be sent back to the caller at a later time. Callers can be stored for later use.
def foo(thing) @pending[thing] = caller do_something_with(thing) noreply def after_thing_processed(thing, result) orig_caller = @pending.delete(thing) orig_caller.reply(result)
Futures
- Sorry, futures are presently unimplemented
Reia supports futures, which allow you to call a method on a remote object without immediately waiting for the return value. This allows the caller to do something else in the meantime. When the caller is ready, it can request the return value of the method. The value is returned immediately if available, otherwise the caller will wait until the value becomes available.
Reia uses the -> operator to obtain a future for a given method. Call a future like a function to obtain its value. The value of a future may be obtained only once; subsequent attempts to retrieve a future's value will cause an error.
>> obj = Foo()
=> #<Object>
>> fut = foo->bar("baz!")
=> #<Future>
>> fut()
=> 42

