branch: externals/websocket commit b77aca6ccf0937601e53b53ec906f9ee4fc5d469 Merge: 23ec19933d 1608341a1c Author: Andrew Hyatt <ahy...@gmail.com> Commit: GitHub <nore...@github.com>
Merge pull request #50 from yuya373/add-nowait-option Make nowait optional, allowing the client to return from websocket-open before the connection is made. --- websocket-functional-test.el | 1 + websocket.el | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/websocket-functional-test.el b/websocket-functional-test.el index 80eb004d7c..cc9ac7080b 100644 --- a/websocket-functional-test.el +++ b/websocket-functional-test.el @@ -116,6 +116,7 @@ wstest-msgs nil) (sleep-for 0.3) (assert (websocket-openp wstest-ws)) + (sleep-for 0.6) (assert (eq 'open (websocket-ready-state wstest-ws))) (assert (null wstest-msgs)) (websocket-send-text wstest-ws "Hi!") diff --git a/websocket.el b/websocket.el index 39a31c3593..e468795246 100644 --- a/websocket.el +++ b/websocket.el @@ -609,7 +609,8 @@ connecting or open." (cl-defun websocket-open (url &key protocols extensions (on-open 'identity) (on-message (lambda (_w _f))) (on-close 'identity) - (on-error 'websocket-default-error-handler)) + (on-error 'websocket-default-error-handler) + (nowait nil)) "Open a websocket connection to URL, returning the `websocket' struct. The PROTOCOL argument is optional, and setting it will declare to the server that this client supports the protocols in the list @@ -679,6 +680,10 @@ describing the invalid header received from the server. `websocket-unparseable-frame': Data in the error is a string describing the problem with the frame. + +`nowait': If NOWAIT is non-nil, +return without waiting for the connection to complete. +Default nil. " (let* ((name (format "websocket to %s" url)) (url-struct (url-generic-parse-url url)) @@ -694,9 +699,9 @@ describing the problem with the frame. (host (url-host url-struct))) (if (eq type 'plain) (make-network-process :name name :buffer nil :host host - :service port :nowait nil) + :service port :nowait nowait) (condition-case-unless-debug nil - (open-network-stream name nil host port :type type :nowait nil) + (open-network-stream name nil host port :type type :nowait nowait) (wrong-number-of-arguments (signal 'websocket-wss-needs-emacs-24 "wss"))))) (signal 'websocket-unsupported-protocol (url-type url-struct))))