MCPcopy
hub / github.com/docsifyjs/docsify / waitForFunction

Function waitForFunction

test/helpers/wait-for.js:14–48  ·  view source on GitHub ↗

* Waits for specified function to resolve to a truthy value. * * @param {Function} fn function to be evaluated until truthy * @param {*} arg optional argument to pass to `fn` * @param {Object} options optional parameters * @returns {Promise} promise which resolves to function result

(fn, arg, options = {})

Source from the content-addressed store, hash-verified

12 * @returns {Promise} promise which resolves to function result
13 */
14function waitForFunction(fn, arg, options = {}) {
15 const settings = {
16 ...defaults,
17 ...options,
18 };
19
20 return new Promise((resolve, reject) => {
21 let timeElapsed = 0;
22
23 const int = setInterval(() => {
24 let result;
25
26 try {
27 result = fn(arg);
28 } catch (e) {
29 // Continue...
30 }
31
32 if (result) {
33 clearInterval(int);
34 resolve(result);
35 }
36
37 timeElapsed += settings.delay;
38
39 if (timeElapsed >= settings.timeout) {
40 const msg = `waitForFunction did not return a truthy value (${
41 settings.timeout
42 } ms): ${fn.toString()}\n`;
43
44 reject(msg);
45 }
46 }, settings.delay);
47 });
48}
49
50/**
51 * Waits for specified CSS selector to be located in the DOM

Callers 1

example.test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…