You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/10/12 15:20:55 UTC

[GitHub] [apisix] membphis commented on a change in pull request #2397: feature(core): implement `core.sleep`

membphis commented on a change in pull request #2397:
URL: https://github.com/apache/apisix/pull/2397#discussion_r503366943



##########
File path: apisix/core/utils.lua
##########
@@ -194,4 +196,22 @@ function _M.validate_header_value(value)
 end
 
 
+local function sleep(sec)
+    if sec <= max_sleep_interval then
+        ngx_sleep(sec)
+        return
+    end
+    ngx_sleep(max_sleep_interval)
+    if exiting() then
+        return
+    end
+    sec = sec - max_sleep_interval
+    sleep(sec)
+end
+
+
+function _M.sleep(sec)

Review comment:
       `_M.sleep = sleep` is enough

##########
File path: apisix/core/utils.lua
##########
@@ -194,4 +196,22 @@ function _M.validate_header_value(value)
 end
 
 
+local function sleep(sec)
+    if sec <= max_sleep_interval then
+        ngx_sleep(sec)
+        return

Review comment:
       `return ngx_sleep(sec)`
   use proper tail recursion is good here

##########
File path: apisix/core/utils.lua
##########
@@ -194,4 +196,22 @@ function _M.validate_header_value(value)
 end
 
 
+local function sleep(sec)
+    if sec <= max_sleep_interval then
+        ngx_sleep(sec)
+        return
+    end
+    ngx_sleep(max_sleep_interval)
+    if exiting() then
+        return
+    end
+    sec = sec - max_sleep_interval
+    sleep(sec)

Review comment:
       `return sleep(sec)` ditto




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org