circuits icon indicating copy to clipboard operation
circuits copied to clipboard

extend fire/call/wait API to include event flags?

Open spaceone opened this issue 8 years ago • 1 comments

If the main loop of circuits run in a thread and in another thread the following pattern is used:

event = self.fire(hello())
event.notify = True

Then we have a race condition where the event might already be processed so that the notify flag is not yet set and therefore not evaluated. A workaround ist to do:

event = hello()
event.notify = True
self.fire(event)

But as the syntax is already in use and it is a nice shortcut we could think about extending the API which would allow the following:

event = self.fire(hello(), notify=True)

spaceone avatar Jan 27 '17 19:01 spaceone

Can we just rework all this? :) I don't like the way I originally implemented this at all :/

The basic idea here away back when was that any event fire would return a special value that acts more like a proxy/promise and subsequent child events from would automagically create a chain such that the original value being "waited on" eventually evaluates correctly.

Consider the following example:

def foo(self):
  x = yield self.fire(add(1, 2))
  y = yield self.fire(mul(x, 2))
  yield y

Very contrived I know but we should just make this better all-round :)

James Mills / prologic

E: [email protected] W: prologic.shortcircuit.net.au

On Fri, Jan 27, 2017 at 11:38 AM, ⁣ Florian Best [email protected] wrote:

If the main loop of circuits run in a thread and in another thread the following pattern is used:

event = self.fire(hello()) event.notify = True

Then we have a race condition where the event might already be processed so that the notify flag is not yet set and therefore not evaluated. A workaround ist to do:

event = hello() event.notify = True self.fire(event)

But as the syntax is already in use and it is a nice shortcut we could think about extending the API which would allow the following:

event = self.fire(hello(), notify=True)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/circuits/circuits/issues/219, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOv-mI2LmDJHF3jeGm2Fnjt-4acU57Kks5rWkfDgaJpZM4LwImr .

prologic avatar Jan 29 '17 04:01 prologic