File tree 3 files changed +32
-3
lines changed
3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,6 @@ def __next__(self):
69
69
self .exc .__traceback__ = None
70
70
raise self .exc
71
71
72
-
73
72
# Pause task execution for the given time (integer in milliseconds, uPy extension)
74
73
# Use a SingletonGenerator to do it without allocating on the heap
75
74
def sleep_ms (t , sgen = SingletonGenerator ()):
@@ -93,6 +92,34 @@ def sleep(t):
93
92
return sleep_ms (int (t * 1000 ))
94
93
95
94
95
+ ################################################################################
96
+ # "Never schedule" object"
97
+ # Don't re-schedule the object that awaits the _never singleton.
98
+ # For internal use only. Some constructs, like `await event.wait()`,
99
+ # work by NOT re-scheduling the task which calls wait(), but by
100
+ # having some other task schedule it later.
101
+ class _Never :
102
+ def __init__ (self ):
103
+ self .state = None
104
+ self .exc = StopIteration ()
105
+
106
+ def __iter__ (self ):
107
+ return self
108
+
109
+ def __await__ (self ):
110
+ return self
111
+
112
+ def __next__ (self ):
113
+ if self .state is not None :
114
+ self .state = None
115
+ return None
116
+ else :
117
+ self .exc .__traceback__ = None
118
+ raise self .exc
119
+
120
+ _never = _Never ()
121
+
122
+
96
123
################################################################################
97
124
# Queue and poller for stream IO
98
125
Original file line number Diff line number Diff line change @@ -62,7 +62,8 @@ async def wait(self):
62
62
self .waiting .push_head (core .cur_task )
63
63
# Set calling task's data to the event's queue so it can be removed if needed
64
64
core .cur_task .data = self .waiting
65
- yield
65
+ core ._never .state = False
66
+ await core ._never
66
67
return True
67
68
68
69
Original file line number Diff line number Diff line change @@ -69,7 +69,8 @@ async def acquire(self):
69
69
# Set calling task's data to the lock's queue so it can be removed if needed
70
70
core .cur_task .data = self .waiting
71
71
try :
72
- yield
72
+ core ._never .state = False
73
+ await core ._never
73
74
except core .CancelledError as er :
74
75
if self .state == core .cur_task :
75
76
# Cancelled while pending on resume, schedule next waiting Task
You can’t perform that action at this time.
0 commit comments