[Bro-Dev] Asynchronous function calls
robin at icir.org
Mon Sep 21 08:26:45 PDT 2015
With Broker, we have the problem that a number of function calls
operate asynchronously so that one needs to wrap them into "when"
statements, which gets cumbersome quickly. One idea we had discussed
in the past is adding synchronous versions with slightly different
semantics (see  for a summary). However, the other day I came
across a new feature in Python 3.5, and I'm now wondering if that
could be a better route for Bro, too.
In a nutshell, Python has added language support for co-routines. From
: "Inside of a coroutine body, the 'await' keyword can be used to
make an expression suspend the execution of the coroutine and wait for
some processing to complete."
data = await db.fetch('SELECT ...')
See  for more.
I think in Bro we could implement somehting like this through the same
infrastructure that "when" uses (with some tweaks, maybe); but for
user code it would be much nicer. Indeed, existing async BiFs, like
for DNS lookups, could then use this as well.
One challenge here is error handling: what to do if the function
doesn't return / fails / times out? Another question would be
performance: what if we have 1000s of these pending? (I don't think we
know the answer for "when"-stmts either though ...)
Robin Sommer * ICSI/LBNL * robin at icir.org * www.icir.org/robin
More information about the bro-dev