mirror of
https://github.com/CFC-Servers/cfc_network_promises.git
synced 2025-03-04 03:03:19 -05:00
Add dTimer dependency
This commit is contained in:
parent
2c63769c19
commit
f521f4f858
@ -2,6 +2,9 @@
|
||||
# cfc_network_promises
|
||||
Network-based promise library
|
||||
|
||||
## Requirements
|
||||
- [cfc_detached_timer](https://github.com/CFC-Servers/cfc_detached_timer)
|
||||
|
||||
## Async + Await
|
||||
This project implements a C#/javascript style async and await functionality.
|
||||
Similarly to Javascript, this is built on top of promises.
|
||||
|
@ -10,7 +10,7 @@ end
|
||||
-- Delay to escape any enclosing pcalls
|
||||
local function delayPromise( prom, method, ... )
|
||||
local data = { ... }
|
||||
timer.Simple( 0, function()
|
||||
dTimer.Simple( 0, function()
|
||||
prom[method]( prom, unpack( data ) )
|
||||
end )
|
||||
end
|
||||
|
@ -1,3 +1,4 @@
|
||||
require( "cfc_detached_timer" )
|
||||
local deferred = include( "network_promises/include/deferred.lua" )
|
||||
promise = deferred -- Create global promise variable for other scripts
|
||||
|
||||
@ -8,3 +9,16 @@ include( "network_promises/http.lua" )
|
||||
include( "network_promises/net.lua" )
|
||||
include( "network_promises/async.lua" )
|
||||
include( "network_promises/util.lua" )
|
||||
|
||||
-- Returns a promise that resolves after t seconds
|
||||
-- fail : Should the promise reject after timeout
|
||||
function NP.timeout( t, fail )
|
||||
local prom = promise.new()
|
||||
local method = fail and prom.reject or prom.resolve
|
||||
|
||||
dTimer.Simple( t, function()
|
||||
method( prom, "Timeout" )
|
||||
end )
|
||||
return prom
|
||||
end
|
||||
|
||||
|
@ -1,17 +1,5 @@
|
||||
NP.http = {}
|
||||
|
||||
-- Returns a promise that resolves after t seconds
|
||||
-- fail : Should the promise reject after timeout
|
||||
function NP.timeout( t, fail )
|
||||
local prom = promise.new()
|
||||
local method = fail and prom.reject or prom.resolve
|
||||
|
||||
timer.Simple( t, function()
|
||||
method( prom, "Timeout" )
|
||||
end )
|
||||
return prom
|
||||
end
|
||||
|
||||
local function responseSuccess( prom, body, status, headers )
|
||||
local isSuccessStatus = math.floor( status / 100 ) == 2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user