|
Home
#A Usage Example The main exampleFriendly Flow allows you to write event driven, multiplexed code which looks like blocking code from a single-client or threaded server. def foo(sock):
data = yield sock.readAll(1000)
#... do interesting stuff with data
yield sock.writeAll("response")Both yield statements above yield to a select() based reactor, and return only when
This allows for the small footprint and ease of understanding of a framework like "Twisted" (reactor based), while providing the programmer with a very well known paradigm: a bunch of statements executed top to bottom. Composition: flatten.pyComposition is also possible. Consider the following normal piece of code def f():
return "f return value"
def g():
return f()This translates into Friendly Flow code in the following manner: def f():
yield RETURN("f return value")
def g()
fReturn = yield f()Why the extra RETURN glue? Well, because we use "whatever else we yield" als tokens for the reactor (blocking for read, write and some other options) we need a special token to designate this value needs to go into the value fReturn at g(). Note also that yielding a generator (a method with yield statements) is interpreted as calling it. Yieldable tokens: scheduler.py
Getting started
Credits and resources
ContactThere's no lists yet. Friendly Flow is currently developed by Klaas van Schelven, Xaba Software. Xaba Software is here: www.xaba.nl (Dutch). Mail Klaas: klaas@vanschelven.com |