File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 128
128
129
129
M .Interrupter = Interrupter
130
130
131
+ --- This is useful for cancelling execution async function
132
+ --- @class AbortSignal
133
+ --- @field aborted boolean
134
+ --- @field private abort_cbs function[]
135
+ local AbortSignal = {}
136
+
137
+ --- @return AbortSignal
138
+ function AbortSignal .new ()
139
+ local obj = {
140
+ aborted = false ,
141
+ abort_cbs = {},
142
+ }
143
+
144
+ setmetatable (obj , { __index = AbortSignal })
145
+ return obj
146
+ end
147
+
148
+ function AbortSignal :abort ()
149
+ if not self .aborted then
150
+ self .aborted = true
151
+ for _ , cb in pairs (self .abort_cbs ) do
152
+ cb ()
153
+ end
154
+ end
155
+ end
156
+
157
+ --- @param cb function
158
+ function AbortSignal :on_abort (cb )
159
+ table.insert (self .abort_cbs , cb )
160
+ end
161
+
162
+ M .AbortSignal = AbortSignal
163
+
131
164
return M
You can’t perform that action at this time.
0 commit comments