Some stuff added

This commit is contained in:
nocturn9x 2020-03-23 18:09:18 +00:00
parent 4dd418db56
commit f63d7477ed
2 changed files with 8 additions and 9 deletions

View File

@ -11,8 +11,8 @@ What works and what does not (21st March 2020 11:22 AM)
- 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
- Scheduling tasks for future execution: V
- Return values of coroutines: V
- Scheduling tasks for future execution: X
"""
@ -40,11 +40,9 @@ async def count(stop, step=1):
async def main():
print("Spawning countdown immediately, scheduling count for 2 secs from now")
task = loop.spawn(countdown(8))
task1 = loop.spawn(count(8, 2))
await giambio.sleep(2)
await task.cancel()
result = await task1.join() # Joining multiple tasks still causes problems
result1 = await task.join()
task1 = loop.schedule(count(8, 2), 2)
result = await task.join()
# result1 = await task1.join() # Joining a scheduled task does not reschedule the parent task
print(result, result1)
print("All done")

View File

@ -71,7 +71,7 @@ class EventLoop:
"""Schedules a task for execution after n seconds"""
self.sequence += 1
task = Task(coroutine)
task = Task(coroutine, self)
heappush(self.paused, (self.clock() + when, self.sequence, task))
return task
@ -120,7 +120,7 @@ class EventLoop:
if coro not in self.joined:
self.joined[coro].append(self.running)
else:
raise AlreadyJoinedError("Joining the same task multiple times is not allowed!")
self.running.throw(AlreadyJoinedError("Joining the same task multiple times is not allowed!"))
def want_sleep(self, seconds):
self.sequence += 1 # Make this specific sleeping task unique to avoid error when comparing identical deadlines
@ -170,6 +170,7 @@ class Task:
return f"giambio.core.Task({self.coroutine}, {self.status}, {self.joined}, {self.result})"
def throw(self, exception: Exception):
self.result = Result(None, exception)
return self.coroutine.throw(exception)
async def cancel(self):