[ANN] lazy.rb 0.9.5 -- transparent futures!

D

Daniel Nugent

Mental, could I perchance persuade you to add an optional parameter to
the Future initializer that accepts a block to be run inside the
rescue clause of the Future's thread?

The situation I am specifically thinking of is this:

I have a number of objects that will want the value resulting from the
Future. I know all of these objects WILL need to access that value.=20
Because the computation in the Future is very expensive, I would like
to raise exceptions on those objects as soon as the thread is caught
so that they can begin handling the error as soon as possible.

So, at the time of the exception, I can lock down the current
subscribers list and then fire off the exception to each of them.=20
Something like this:

future(lambda{|exception| lock.synchronize{subscribers.each{|s|
s.raise(exception)}}}){holy_crap_long_execution}
 
M

MenTaLguY

--=-Ifb8m4jC3rG/6XZFK5tI
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Yep, it was a bug in the new RubyGems server-side indexing software.=20
Should be fixed now. Give it another try...
=20
gem install blankslate -s http://onestepback.org/betagems

Hmm. Okay, for lazy.rb there are a couple things I would need from
BlankSlate:

- the ability to "let through" a few additional methods
(just Object#class at the moment, but there may be more later)

- to be able to hide Object#instance_eval

Maybe the best thing would be a factory that creates customized
BlankSlate-like classes, roughly similar to the way Struct works.

Thoughts?

-mental

--=-Ifb8m4jC3rG/6XZFK5tI
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBEAOWNSuZBmZzm14ERAgzkAKDbwFXRBrVli794qYFpvpSYE0Qt3QCbBIc5
o05yv6AGF/1ytVGidTXg1wM=
=Xvg+
-----END PGP SIGNATURE-----

--=-Ifb8m4jC3rG/6XZFK5tI--
 
C

Caleb Clausen

Hmm. Okay, for lazy.rb there are a couple things I would need from
BlankSlate:

- the ability to "let through" a few additional methods
(just Object#class at the moment, but there may be more later)

- to be able to hide Object#instance_eval

I have a rather mutated version of BlankSlate (as a module) which
supports both of these.
You can use it something like this:

class Foo
include BlankSlate
hide :instance_eval
restore :class
end

Foo.new.instance_eval{} #=3D> raises NoMethodError
Foo.new.class #=3D> Foo

Is there any chance these features could be included in the gem? I'd
love to use it myself, but I need my various changes to it too.

Here's the code:


module BlankSlate
module ClassMethods
def restore(*names)
names.each{|name| alias_method name, "##{name}"}
end
def hide(*names)
names.each do|name|
undef_method name if instance_methods.include?(name.to_s)
end
end
end

def BlankSlate.included(othermod)
othermod.instance_eval {
instance_methods.each { |m|
#nothing is thrown away forever, just renamed in a strange way
alias_method "##{m}", m #archive m
undef_method m unless m =3D~ /^__/ || m=3D=3D'instance_eval'
}
extend BlankSlate::ClassMethods
}
end
end
 
J

Jim Weirich

MenTaLguY said:
Hmm. Okay, for lazy.rb there are a couple things I would need from
BlankSlate:

- the ability to "let through" a few additional methods
(just Object#class at the moment, but there may be more later)

- to be able to hide Object#instance_eval

Maybe the best thing would be a factory that creates customized
BlankSlate-like classes, roughly similar to the way Struct works.

Instance_eval can be hidden with a call to hide. This class method is
trivial to reimplement, although the general case might need something
like Caleb suggested.

class BS < BlankSlate
hide :instance_eval
def class
BS
end
end
 
M

Minkoo Seo

Hi mental. Thank you for the really nice library.

I'm sorry if this bothers you, but I have no idea what "circular
programming" is. Could you give me an example? Especially, what does
"matryoshka = demand( promise { |result| [result] } )" mean?

I also suggest that you should upload the description posted here to
your own website(http://moonbase.rydia.net/software/lazy.rb/), so that
people can find out what lazy.rb really is. IMHO, RDoc itself is not
sufficient.

- Minkoo Seo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] lazy.rb 0.2 1
[ANN] Futures and JRuby: The Omnibus Concurrency Library 0.2.1 3
[ANN] lazy.rb 7
[ANN] lazy.rb 0.1 0
[ANN] rs 0.1.2 0
lazy fibs 0
[ANN] XMLable 0.1.1 0
Calcul XOR : array , times. 3

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top