MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / enqueueWithDelay

Function enqueueWithDelay

src/internalBinding/timers.cc:25–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 */
24
25static bool enqueueWithDelay(JSContext *cx, unsigned argc, JS::Value *vp) {
26 if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) {
27 // quit, exit or sys.exit was called (and raised SystemExit)
28 return false;
29 }
30
31 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
32 JS::HandleValue jobArgVal = args.get(0);
33 double delaySeconds = args.get(1).toNumber();
34 bool repeat = args.get(2).toBoolean();
35 JS::HandleValue debugInfo = args.get(3);
36
37 // Convert to a Python function
38 JS::RootedValue jobArg(cx, jobArgVal);
39 PyObject *job = pyTypeFactory(cx, jobArg);
40 // Schedule job to the running Python event-loop
41 PyEventLoop loop = PyEventLoop::getRunningLoop();
42 if (!loop.initialized()) return false;
43 PyEventLoop::AsyncHandle::id_t handleId = loop.enqueueWithDelay(job, delaySeconds, repeat);
44 Py_DECREF(job);
45
46 // Set debug info for the WTFPythonMonkey tool
47 auto handle = PyEventLoop::AsyncHandle::fromId(handleId);
48 handle->setDebugInfo(pyTypeFactory(cx, debugInfo));
49
50 // Return the `timeoutID` to use in `clearTimeout`
51 args.rval().setNumber(handleId);
52 return true;
53}
54
55static bool cancelByTimeoutId(JSContext *cx, unsigned argc, JS::Value *vp) {
56 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);

Callers 3

setTimeoutFunction · 0.85
setImmediateFunction · 0.85
setIntervalFunction · 0.85

Calls 5

pyTypeFactoryFunction · 0.85
getMethod · 0.80
initializedMethod · 0.80
enqueueWithDelayMethod · 0.80
setDebugInfoMethod · 0.80

Tested by

no test coverage detected