Avatar

@alp

14 likes20 public vals
Joined February 28, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
export let confession = `
Dear val.town overlords,
I pen this note with a heavy heart, for I have sinned. My folly unfolded amidst the
high-paced life of a val.town developer, where I danced too close to the flames of
concurrency, blinded by a mix of audacious hope and foolish courage.
Deep down in the foundational layers of my code, I knew that our sacred texts,
the guidelines of val.town, proclaim that fetchProxy was not built to support concurrency.
Yet, intoxicated by ambition and sprinkled with a dash of desperate creativity, I dared
to summon multiple instances of this sacred method.
Emboldened by my insubordination, I threw them into the tumultuous world, dispatching them
in an unrestrained frenzy. I dreamt of an orchestra of parallel operations, each blissfully
retrieving data from the sanctified servers beyond, and defying the fundamental laws of
single-threadedness.
To my surprise and secret delight, it worked! I should have been greeted by an error-storm,
each one a blazing reminder of my transgressions. Instead, I was met with successful
responses, each one a silently nodding accomplice to my disobedience.
Yet here I am, swamped with guilt. Despite my code running smoothly, the weight of my
transgressions bears heavily upon me. I see the sneaky shortcuts in my code, each one a
deceptively functional fetchProxy instance, and I can't help but feel like a sneaky
impostor, a charlatan.
I beseech you, val.town overlords, for guidance in my journey towards understanding and
respecting the limitations of fetchProxy. May the power of async and await continue to
guide me, and may I resist the seductive whispers of unsupported, yet seemingly functional,
concurrency.
Forgive me, val.town, for while I reaped success, I knew deep down that I had treaded on
shaky ground.
Yours in deepest regret,
A guilt-ridden coder
`;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { fetch } from "https://esm.town/v/std/fetch";
export const test_concurrencyDoesntWork = (async () => {
const fetchDelayedResponse = async (index: number) => {
const start = Date.now();
const response = await fetch(
"https://api.val.town/v1/express/alp.proxyFetch1",
{
method: "POST",
body: JSON.stringify({
url: "https://hub.dummyapis.com/delay?seconds=1",
}),
}
);
console.log(
`Returned data for ${index}, took:`,
(Date.now() - start) / 1000,
"seconds"
);
};
const fetchDelayedResponseWithLoadBalancer = async (index: number) => {
const start = Date.now();
const response = await fetch(
`https://api.val.town/v1/express/alp.proxyFetch${index}`,
{
method: "POST",
body: JSON.stringify({
url: "https://hub.dummyapis.com/delay?seconds=2",
}),
}
);
console.log(
`Returned data for ${index}, took:`,
(Date.now() - start) / 1000,
"seconds"
);
};
console.log("w/o load balancer");
await Promise.all([
fetchDelayedResponse(1),
fetchDelayedResponse(2),
fetchDelayedResponse(3),
fetchDelayedResponse(4),
fetchDelayedResponse(5),
]);
console.log("w/ load balancer");
await Promise.all([
fetchDelayedResponseWithLoadBalancer(1),
fetchDelayedResponseWithLoadBalancer(2),
fetchDelayedResponseWithLoadBalancer(3),
1
2
3
4
5
6
7
8
9
10
11
12
13
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch10 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch9 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch8 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch7 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch6 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch5 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch4 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch3 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
}
};