I'm writing an app which needs to fire off a large number of threads, have them process something and pass the result back using a callback.
The problem I've got is that I need to be able to wait for all the threads to finish then do some more work. The example code uses a sleep at the end to have the main script wait long enough for everything to finish before exiting, I can't do this as I've no idea how long the threads will take and it isn't the "right" way to do it anyway.
If you really want to wait for an actor to exit, call #terminate on it then use Celluloid::Actor.join(actor)
Don't futures block till they've returned? I started with those but
those but then moved off to this approach.
I read that #terminate waits till all the current threads finish
then exits just dropping any that haven't been started yet, isn't that the case?
On 19 Jan 2015 17:50, "Tony Arcieri" <bas...@gmail.com> wrote:
>
> On Mon, Jan 19, 2015 at 2:35 PM, Robin Wood <ro...@digi.ninja> wrote:
>>
>> Don't futures block till they've returned? I started with those but
>> those but then moved off to this approach.
>
>
> They block if you call `#value` on them and they aren't ready.
>
So use a future but then use the callback to get the result rather than calling #value, I hadn't thought of that approach, sounds good.
>>
>> I read that #terminate waits till all the current threads finish
>
>
> Do you mean tasks?
>
Possibly. I just remember reading that it let what was running finish but didn't start anything new so I probably do mean tasks.
>>
>> then exits just dropping any that haven't been started yet, isn't that the case?
>
>
> If you're using synchronous calls or futures, they won't be "dropped", they will cause an error in the caller (or consumer of the value).
Do they all still run and just send back errors that can be ignored or do they die in some way which causes the error?
Do they all still run and just send back errors that can be ignored or do they die in some way which causes the error?
Thanks, will try that. Not heard of live lock before, what does that mean in terms of the threads?
Robin
--
Thanks, will try that. Not heard of live lock before, what does that mean in terms of the threads?
Is that because the join forces everything into the first actor meaning the rest can't run?
Robin
Is that because the join forces everything into the first actor meaning the rest can't run?
Ok makes sense, thanks.
If I wanted to use a pool would I just pull a list of actors out of the pool or is there a different way to get them?
--