aboutsummaryrefslogtreecommitdiff
path: root/sx-request.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2015-01-02 01:06:23 -0500
committerSean Allred <code@seanallred.com>2015-01-02 01:06:23 -0500
commitcaad878334e548de2e5157f692746c21dee3ff0d (patch)
tree8bdd66af9f0c5308edbd3fcb1b20435e17632d38 /sx-request.el
parentf3bc9b692da7305acec568122992ee62dca45496 (diff)
Introduce anti-throttling delay
Diffstat (limited to 'sx-request.el')
-rw-r--r--sx-request.el7
1 files changed, 5 insertions, 2 deletions
diff --git a/sx-request.el b/sx-request.el
index f9b93ea..ba5f6f7 100644
--- a/sx-request.el
+++ b/sx-request.el
@@ -95,10 +95,12 @@ number of requests left every time it finishes a call."
;;; Making Requests
(defun sx-request-all-items (method &optional args request-method
- stop-when process-function)
+ process-function stop-when delay)
"Call METHOD with ARGS until there are no more items.
STOP-WHEN is a function that takes the entire response and
-returns non-nil if the process should stop.
+returns non-nil if the process should stop. DELAY is the number
+of seconds (possibly a float value) to wait after each request is
+made (to avoid throttling). The default value is 0.25.
All other arguments are identical to `sx-request-make', but
PROCESS-FUNCTION is given the default value of `identity' (rather
@@ -118,6 +120,7 @@ access the response wrapper."
return-value
(vconcat return-value
(cdr (assoc 'items response))))
+ (sleep-for (or delay 0.25))
(setq response
(sx-request-make method `((page . ,current-page) ,@args)
request-method process-function)))