MCPcopy Index your code
hub / github.com/bigskysoftware/_hyperscript / getProxy

Method getProxy

src/ext/socket.js:75–124  ·  view source on GitHub ↗
(timeout)

Source from the content-addressed store, hash-verified

73 var socket = new WebSocket(parseUrl(url.evalStatically()));
74
75 function getProxy(timeout) {
76 return new Proxy(
77 {},
78 {
79 get: function (obj, property) {
80 if (PROXY_BLACKLIST.includes(property)) {
81 return null;
82 } else if (property === "noTimeout") {
83 return getProxy(-1);
84 } else if (property === "timeout") {
85 return function (i) {
86 return getProxy(parseInt(i));
87 };
88 } else {
89 return function () {
90 var uuid = genUUID();
91 var args = [];
92 for (var i = 0; i < arguments.length; i++) {
93 args.push(arguments[i]);
94 }
95 var rpcInfo = {
96 iid: uuid,
97 function: property,
98 args: args,
99 };
100 socket = socket ? socket : new WebSocket(parseUrl(url.evalStatically())); //recreate socket if needed
101 socket.send(JSON.stringify(rpcInfo));
102
103 var promise = new Promise(function (resolve, reject) {
104 promises[uuid] = {
105 resolve: resolve,
106 reject: reject,
107 };
108 });
109
110 if (timeout >= 0) {
111 setTimeout(function () {
112 if (promises[uuid]) {
113 promises[uuid].reject("Timed out");
114 }
115 delete promises[uuid];
116 }, timeout); // TODO configurable?
117 }
118 return promise;
119 };
120 }
121 },
122 }
123 );
124 }
125
126 var rpcProxy = getProxy(defaultTimeout);
127

Callers

nothing calls this directly

Calls 4

genUUIDFunction · 0.70
parseUrlFunction · 0.70
setTimeoutFunction · 0.50
evalStaticallyMethod · 0.45

Tested by

no test coverage detected