mirror of https://github.com/nocturn9x/giambio.git
Added todos and comments
This commit is contained in:
parent
25c404c961
commit
c30561b18c
|
@ -3,6 +3,19 @@ import giambio
|
|||
|
||||
loop = giambio.EventLoop()
|
||||
|
||||
"""
|
||||
|
||||
What works and what does not
|
||||
|
||||
- Run tasks concurrently: V
|
||||
- Join mechanism: V
|
||||
- Sleep mechanism: V
|
||||
- Cancellation mechanism: V
|
||||
- Exception propagation: V
|
||||
- Concurrent I/O: X Note: I/O would work only when a task is joined (weird)
|
||||
- Return values of coroutines: X Note: Return values ARE actually stored in task objects properly, but are messed up later when joining tasks
|
||||
|
||||
"""
|
||||
|
||||
async def countdown(n):
|
||||
while n > 0:
|
||||
|
|
|
@ -7,7 +7,7 @@ from .exceptions import AlreadyJoinedError, CancelledError
|
|||
import traceback
|
||||
from timeit import default_timer
|
||||
from time import sleep as wait
|
||||
|
||||
from .socket import AsyncSocket
|
||||
|
||||
|
||||
class EventLoop:
|
||||
|
@ -47,7 +47,7 @@ class EventLoop:
|
|||
try:
|
||||
method, *args = self.running.run() # Sneaky method call, thanks to David Beazley for this ;)
|
||||
getattr(self, method)(*args)
|
||||
except StopIteration as e:
|
||||
except StopIteration as e: # TODO: Fix this return mechanism, it looks like the return value of the child task gets "replaced" by None at some point
|
||||
self.running.ret_value = e.args[0] if e.args else None # Saves the return value
|
||||
self.to_run.extend(self.joined.pop(self.running, ())) # Reschedules the parent task
|
||||
except CancelledError:
|
||||
|
@ -158,7 +158,7 @@ def sleep(seconds: int):
|
|||
|
||||
|
||||
@types.coroutine
|
||||
def want_read(sock: socket.socket):
|
||||
def want_read(sock: socket.socket): # TODO: Fix this and make it work also when tasks are not joined
|
||||
"""'Tells' the event loop that there is some coroutine that wants to read from the passed socket"""
|
||||
|
||||
yield "want_read", sock
|
||||
|
|
|
@ -5,14 +5,13 @@ Basic abstraction layer for giambio asynchronous sockets
|
|||
"""
|
||||
|
||||
|
||||
from .core import EventLoop
|
||||
import socket
|
||||
|
||||
|
||||
class AsyncSocket(object):
|
||||
"""Abstraction layer for asynchronous sockets"""
|
||||
|
||||
def __init__(self, sock: socket.socket, loop: EventLoop):
|
||||
def __init__(self, sock: socket.socket, loop):
|
||||
self.sock = sock
|
||||
self.sock.setblocking(False)
|
||||
self.loop = loop
|
||||
|
|
Loading…
Reference in New Issue