by shanemhansen · 3y ago · 0 comments
So twisted code can actually look like:
@inlineCallbacks
def doIt():
responseBody = yield makeRequest("GET", "/users")
returnValue(json.loads(responseBody))
iirc `returnValue` throws an exception of a specific type. It's ugly, but it's also the logical implementation of async on top of yield/generators.Some of our initial code snippets:
# Twisted
def __protocolSendRaw(self, name, args=""): deferred = defer.Deferred() self.__EventQueue.append((name, deferred)) self.rawSend("%s %s" % (name, args)) return deferred
# Gevent
def _protocol_sendmsg(self, name, args=None, async=False): if self._closing_state: return Event() _async_res = gevent.event.AsyncResult() _uuid, event = _async_res.get() return event
> PLIVO (an abbreviation for ongoing life-threatening violence) is a procedure for cooperation between the police, the fire service, the rescue service and the healthcare system in incidents where life-threatening violence is perpetrated against several people.
Absolutely fuck yield-raise based async implementations. Just remembering those induces psychic damage; implementing async as a massive hack on top of the language is impressive but also the kind of thing we're going to whisper to junior engineers as scary campfire stories for DECADES.
async def doIt():
responseBody = await makeRequest("GET", "/users")
return json.loads(responseBody)
See https://patrick.cloke.us/posts/2021/06/11/converting-twisted...