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

Function async_fn

tests/python/test_xhr.py:33–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31 thread.start()
32
33 async def async_fn():
34 assert "get response" == await pm.eval("""
35 new Promise(function (resolve, reject) {
36 let xhr = new XMLHttpRequest();
37 xhr.open('GET', 'http://localhost:4001');
38
39 xhr.onload = function ()
40 {
41 if (this.status >= 200 && this.status < 300)
42 {
43 resolve(this.response);
44 }
45 else
46 {
47 reject(new Error(JSON.stringify({
48 status: this.status,
49 statusText: this.statusText
50 })));
51 }
52 };
53
54 xhr.onerror = function (ev)
55 {
56 reject(ev.error);
57 };
58 xhr.send();
59 });
60 """)
61
62 post_result = await pm.eval("""
63 new Promise(function (resolve, reject)
64 {
65 let xhr = new XMLHttpRequest();
66 xhr.open('POST', 'http://localhost:4001');
67
68 xhr.onload = function ()
69 {
70 if (this.status >= 200 && this.status < 300)
71 {
72 resolve(this.response);
73 }
74 else
75 {
76 reject(new Error(JSON.stringify({
77 status: this.status,
78 statusText: this.statusText
79 })));
80 }
81 };
82
83 xhr.onerror = function (ev)
84 {
85 console.log(ev)
86 reject(ev.error);
87 };
88
89 xhr.send(JSON.stringify({fromPM: "snakesandmonkeys"}));
90 })

Callers 1

test_xhrFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected