ruby-concurrency / ruby-concurrency/concurrent-ruby
Waiting for Actor termination?
Nessuno ha ancora preso questa issue.
- Lingua principale
- Ruby
- Stelle
- 5.8k
- Fork
- 420
- Merge medio
- 20h 45m
- PR unite (30g)
- 4
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- ruby
- Ambito
- backend
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100