Asynchronous function calls

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 [1] 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
[2]: "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 [2] 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 ...)


[2] Python 3.5 will Support Async/Await Asynchronous Programming