Commits

Anonymous committed 1bf42f4

sleep() support

Comments (0)

Files changed (2)

concussion/__init__.py

 import logmod
 log = logmod.log
-from core import until, until_eol, bytes, Connection, ConnectionClosed
+from timers import call_later, call_every
+from core import until, until_eol, bytes, sleep, Connection, ConnectionClosed
 from app import Application, Service

concussion/core.py

 
 from concussion import pipeline
 from concussion import buffer
+from concussion import call_later
 
 class ConnectionClosed(socket.error): pass
 
 class bytes(object):
 	def __init__(self, bytes):
 		self.sentinel = sentinel
+
+class sleep(object):
+	def __init__(self, duration):
+		self.duration = duration
 	
 class Connection(object):
 	def __init__(self, sock, addr, connection_handler):
 			if res:
 				self.iterate(res)
 
+	def wake(self):
+		self.iterate()
+
 	def iterate(self, n_val=None):
 		while True:
 			try:
 				n_val = self.buffer.check()
 				if n_val == None:
 					break
+			elif type(ret) is sleep:
+				call_later(ret.duration, self.wake)
+				break
 
 		if not self.pipeline.empty:
 			self.set_writable(True)