mirror of https://github.com/nocturn9x/giambio.git
Some stuff added
This commit is contained in:
parent
4dd418db56
commit
f63d7477ed
|
@ -11,8 +11,8 @@ What works and what does not (21st March 2020 11:22 AM)
|
||||||
- Cancellation mechanism: V
|
- Cancellation mechanism: V
|
||||||
- Exception propagation: V
|
- Exception propagation: V
|
||||||
- Concurrent I/O: X Note: I/O would work only when a task is joined (weird)
|
- 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
|
- Return values of coroutines: V
|
||||||
- Scheduling tasks for future execution: V
|
- Scheduling tasks for future execution: X
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -40,11 +40,9 @@ async def count(stop, step=1):
|
||||||
async def main():
|
async def main():
|
||||||
print("Spawning countdown immediately, scheduling count for 2 secs from now")
|
print("Spawning countdown immediately, scheduling count for 2 secs from now")
|
||||||
task = loop.spawn(countdown(8))
|
task = loop.spawn(countdown(8))
|
||||||
task1 = loop.spawn(count(8, 2))
|
task1 = loop.schedule(count(8, 2), 2)
|
||||||
await giambio.sleep(2)
|
result = await task.join()
|
||||||
await task.cancel()
|
# result1 = await task1.join() # Joining a scheduled task does not reschedule the parent task
|
||||||
result = await task1.join() # Joining multiple tasks still causes problems
|
|
||||||
result1 = await task.join()
|
|
||||||
print(result, result1)
|
print(result, result1)
|
||||||
print("All done")
|
print("All done")
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ class EventLoop:
|
||||||
"""Schedules a task for execution after n seconds"""
|
"""Schedules a task for execution after n seconds"""
|
||||||
|
|
||||||
self.sequence += 1
|
self.sequence += 1
|
||||||
task = Task(coroutine)
|
task = Task(coroutine, self)
|
||||||
heappush(self.paused, (self.clock() + when, self.sequence, task))
|
heappush(self.paused, (self.clock() + when, self.sequence, task))
|
||||||
return task
|
return task
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ class EventLoop:
|
||||||
if coro not in self.joined:
|
if coro not in self.joined:
|
||||||
self.joined[coro].append(self.running)
|
self.joined[coro].append(self.running)
|
||||||
else:
|
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):
|
def want_sleep(self, seconds):
|
||||||
self.sequence += 1 # Make this specific sleeping task unique to avoid error when comparing identical deadlines
|
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})"
|
return f"giambio.core.Task({self.coroutine}, {self.status}, {self.joined}, {self.result})"
|
||||||
|
|
||||||
def throw(self, exception: Exception):
|
def throw(self, exception: Exception):
|
||||||
|
self.result = Result(None, exception)
|
||||||
return self.coroutine.throw(exception)
|
return self.coroutine.throw(exception)
|
||||||
|
|
||||||
async def cancel(self):
|
async def cancel(self):
|
||||||
|
|
Loading…
Reference in New Issue