MCPcopy Create free account
hub / github.com/pywebio/PyWebIO / WaitChange

Function WaitChange

webiojs/src/models/pin.ts:38–62  ·  view source on GitHub ↗
(names: string[], timeout: number)

Source from the content-addressed store, hash-verified

36let resident_onchange_callbacks: { [name: string]: ((val: any) => void)[] } = {}; // name->[]
37
38export function WaitChange(names: string[], timeout: number) {
39 let promises = [];
40 let callback_ids: { [name: string]: string } = {};
41 for (let name of names) {
42 promises.push(new Promise(resolve => {
43 callback_ids[name] = register_on_change(name, value => {
44 resolve({'name': name, 'value': value})
45 });
46 }));
47 }
48 if (timeout) {
49 promises.push(new Promise(resolve => {
50 setTimeout(() => {
51 resolve(null);
52 }, timeout * 1000);
53 }));
54 }
55 return Promise.race(promises).then((val) => {
56 for (let name of names) {
57 let callback_id = callback_ids[name];
58 delete disposable_onchange_callbacks[name][callback_id];
59 }
60 return val;
61 });
62}
63
64export function PinChangeCallback(name: string, callback: null | ((val: any) => void), clear: boolean) {
65 if (!(name in resident_onchange_callbacks) || clear)

Callers 1

handle_messageMethod · 0.90

Calls 2

register_on_changeFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…