File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change 2
2
import pythonmonkey as pm
3
3
import asyncio
4
4
5
- def test_timers_unref ():
5
+ def test_setTimeout_unref ():
6
6
async def async_fn ():
7
7
obj = {'val' : 0 }
8
8
pm .eval ("""(obj) => {
@@ -17,6 +17,18 @@ async def async_fn():
17
17
return True
18
18
assert asyncio .run (async_fn ())
19
19
20
+ def test_setInterval_unref ():
21
+ async def async_fn ():
22
+ obj = {'val' : 0 }
23
+ pm .eval ("""(obj) => {
24
+ setInterval(()=>{ obj.val++ }, 200).unref()
25
+ setTimeout(()=>{ }, 500)
26
+ }""" )(obj )
27
+ await pm .wait () # It should stop after the setTimeout timer's 500ms.
28
+ assert obj ['val' ] == 2 # The setInterval timer should only run twice (500 // 200 == 2)
29
+ return True
30
+ assert asyncio .run (async_fn ())
31
+
20
32
def test_finished_timer_ref ():
21
33
async def async_fn ():
22
34
# Making sure the event-loop won't be activated again when a finished timer gets re-refed.
You can’t perform that action at this time.
0 commit comments