ruby-concurrency / ruby-concurrency/concurrent-ruby
Waiting for Actor termination?
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Ruby
- Estrellas
- 5.8k
- Forks
- 420
- Merge medio
- 20 h 45 min
- PR fusionados (30 d)
- 4
Descripción
Is there an easy way to wait for an Actor to terminate? I'm aware that I can wait till all messages are processed:
actor = MyActor.spawn(name: 'actor')
actor << :dostuff
actor.ask(:await).wait
or wait for the actor to respond (which AFAIK is the same)
actor = MyActor.spawn(name: 'actor')
actor << :dostuff
actor.ask(:some_result).value # or actor.ask!(:some_result)
but both are not what I'm looking for. I want to know how to block until an actor is terminated when the actor has asynchronous execution itself:
class MyActor < Concurrent::Actor::Context
def on_message(message)
case message
when :start
promises = 10.times.map do |n|
Concurrent::Promises.future do
sleep 1
n
end
end
Concurrent::Promises.zip(*promises).then do
self.tell :terminate!
end
Concurrent::Actor::Behaviour::MESSAGE_PROCESSED
else
pass
end
end
end
my_actor = MyActor.spawn(name: 'actor')
my_actor.tell(:start)
# How to do this, as this is obviously not great:
loop do
break if my_actor.ask!(:terminated?)
end
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Start at Concurrent::Actor::Context and the actor lifecycle messages shown in the issue, then trace how termination state is currently exposed. No file or test is named; done means providing a non-polling way to wait for completion after asynchronous work finishes, with coverage for the future-based example.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- ruby
- Área
- backend
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100