@noita-ts/pollnet 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/async.d.ts +1 -0
- package/dist/async.lua +6 -6
- package/package.json +1 -1
package/dist/async.d.ts
CHANGED
package/dist/async.lua
CHANGED
|
@@ -20,7 +20,7 @@ do
|
|
|
20
20
|
--- Run `body` inside a reactor coroutine and get its completion as a Promise.
|
|
21
21
|
-- `body` may freely use socket.await() / other yield-based pollnet APIs.
|
|
22
22
|
-- Errors inside body reject the promise.
|
|
23
|
-
compat.asyncify = function(
|
|
23
|
+
compat.asyncify = function(reactor, body)
|
|
24
24
|
return __TS__New(
|
|
25
25
|
__TS__Promise,
|
|
26
26
|
function(____, resolve, reject)
|
|
@@ -32,7 +32,7 @@ do
|
|
|
32
32
|
local ____try, ____hasReturned = pcall(function()
|
|
33
33
|
resolve(
|
|
34
34
|
nil,
|
|
35
|
-
body(
|
|
35
|
+
body()
|
|
36
36
|
)
|
|
37
37
|
end)
|
|
38
38
|
if not ____try then
|
|
@@ -46,7 +46,7 @@ do
|
|
|
46
46
|
--- Parks the *current coroutine* until the promise settles, then returns its
|
|
47
47
|
-- value or rethrows its rejection.
|
|
48
48
|
-- Only call from inside a reactor coroutine (`reactor.run(() => { .. HERE .. })`).
|
|
49
|
-
compat.yieldPromise = function(
|
|
49
|
+
compat.yieldPromise = function(p)
|
|
50
50
|
local done = false
|
|
51
51
|
local ok = false
|
|
52
52
|
local result
|
|
@@ -87,14 +87,14 @@ function AsyncReactor.prototype.poll(self)
|
|
|
87
87
|
return self.reactor:update()
|
|
88
88
|
end
|
|
89
89
|
function AsyncReactor.prototype.spawn(self, body)
|
|
90
|
-
return ____exports.compat
|
|
90
|
+
return ____exports.compat.asyncify(self.reactor, body)
|
|
91
91
|
end
|
|
92
92
|
function AsyncReactor.prototype.runServer(self, server_sock, client_body)
|
|
93
93
|
server_sock:on_connection(function(client_sock, addr)
|
|
94
94
|
self.reactor:run(function()
|
|
95
|
-
local r = client_body(
|
|
95
|
+
local r = client_body(client_sock, addr)
|
|
96
96
|
if __TS__InstanceOf(r, __TS__Promise) then
|
|
97
|
-
____exports.compat
|
|
97
|
+
____exports.compat.yieldPromise(r)
|
|
98
98
|
end
|
|
99
99
|
end)
|
|
100
100
|
end)
|