GithubHelp home page GithubHelp logo

Comments (15)

tutysara avatar tutysara commented on July 29, 2024

I guess we need to allow configuring nrepl-sync-request-timeout variable in clomacs

from ejc-sql.

kostafey avatar kostafey commented on July 29, 2024

User can change nrepl-sync-request-timeout directly, clomacs is trying to be close to CIDER as much as possible. But there are some ideas to do:

  1. nrepl-sync-request-timeout should be mentioned in ejc-sql README.
  2. Timeout should have possibility to be passed to ejc-eval-user-sql-at-point as prefix number,
    e.g. M-6 M-0 C-c C-c - eval SQL with 60 sec timeout.
  3. For autocomplete we should eval SQL asynchronously.

from ejc-sql.

tutysara avatar tutysara commented on July 29, 2024

most of my queries take more than a min, I had set nrepl-sync-request-timeout to 60 sec in my .spacemacs file and it works, ty.

For making autocomplete to work async, do we have anything in clomacs that support async execution?

from ejc-sql.

kostafey avatar kostafey commented on July 29, 2024

do we have anything in clomacs that support async execution?

Not yet.

from ejc-sql.

tutysara avatar tutysara commented on July 29, 2024

ok sure, can we add this as an enhancement to clomacs and use it for long running calls in ejc-sql.

from ejc-sql.

tutysara avatar tutysara commented on July 29, 2024

Another idea is to load and cache the database structure in the clojure side and use the sync requests as usual.

from ejc-sql.

kostafey avatar kostafey commented on July 29, 2024

Database structure is already cached in EmacsLisp side. But it's an interesting idea. EmacsLisp request for database structure data can start async Clojure (probably long-running) request and receive cached data or empty data (if request still running) immediately.

from ejc-sql.

tutysara avatar tutysara commented on July 29, 2024

Tried writing a async version of the clomacs-defun macro, here is what i have

;;;###autoload
(cl-defmacro clomacs-defun-async (el-func-name
                             cl-func-name
                             callback-func-name
                            &optional &key
                            (doc nil)
                            (return-type :string)
                            (return-value :value)
                            lib-name
                            namespace)
  "Wrap CL-FUNC-NAME, evaluated on clojure side by EL-FUNC-NAME.
DOC - optional elisp function docstring (when nil it constructed from
underlying clojure entity docstring if possible).
RETURN-TYPE possible values are listed in the CLOMACS-POSSIBLE-RETURN-TYPES,
or it may be a custom function (:string by default).
RETURN-VALUE may be :value or :stdout (:value by default)."
  (cl-multiple-value-bind
      (doc namespace-str cl-entity-full-name)
      (clomacs-prepare-vars cl-func-name
                            :doc doc
                            :namespace namespace)
    `(defun ,el-func-name (&rest attributes)
       ,doc
       (clomacs-ensure-nrepl-run ,lib-name)
       (let* ((attrs ""))
         (dolist (a attributes)
           (setq attrs (concat attrs " "
                               (clomacs-format-arg a))))
         (let* ((connection (clomacs-get-connection ,lib-name))
                (session (clomacs-get-session connection)))
                 (nrepl-request:eval
                  (concat
                   (if ',namespace
                       (concat "(require '" ',namespace-str ") ") "")
                   "(" ',cl-entity-full-name attrs ")")
                  (lambda (result)
                    (let* ((el-result (clomacs-get-result
                                       result ,return-value ',return-type ',namespace)))
                      (message "result %s :: el-result %s" result el-result)
                      (if el-result
                          (,callback-func-name el-result))))
                  connection
                  session))
         ))))

and the test code

The following tests works as well, had verified them manually, couldn't find a way to test async calls

(defun result-handler (result)
  (message "Result: %s" result))


(clomacs-defun-async summ-1 * (lambda (result)
                                (message "Result: %s" result)
                                result))
(summ-1 3 5 9)

(clomacs-defun-async summ-2 + result-handler :return-type :number)
(summ-2 2 3)


(clomacs-defun-async summ-3 + result-handler :return-type string-to-int)
(summ-3 2 3)

(clomacs-defun-async str str result-handler)
(str 2 "str")

(clomacs-defun-async get-property System/getProperty result-handler)
(get-property "java.version")

(clomacs-defun-async make-clojure-list list result-handler :return-type :list)
(make-clojure-list 1 2 3)

(clomacs-defun-async make-clojure-vector vector result-handler :return-type :list)
(make-clojure-vector 1 2 3)

Values can be null when async call returns status and completion, so added a null check in the format method

(defun clomacs-format-result (raw-string return-type)
  "Format Elisp representation of Clojure evaluation result."
  (cl-assert return-type)
  (if raw-string
      ...)))) ))

from ejc-sql.

tutysara avatar tutysara commented on July 29, 2024

I see the changes adapted in clomacs, ty. Let me get the latest version check and see

from ejc-sql.

kostafey avatar kostafey commented on July 29, 2024

I see the changes adapted in clomacs

That is a rough version, but feel free to play with it.

from ejc-sql.

kostafey avatar kostafey commented on July 29, 2024

Ok, looks like there is no way to prevent unwanted calls for callback except checking for result is not nil.

from ejc-sql.

tutysara avatar tutysara commented on July 29, 2024

no way to prevent unwanted calls for callback except checking for result is not nil.

yes, nprel calls the callback for value and status update. I was looking into nrepl source code to see if they can send multiple messages with value, if they are sending multiple then we may have to collect all values till the status is done and then call the callback with the complete value.

from ejc-sql.

kostafey avatar kostafey commented on July 29, 2024

@tutysara you can test last activity about this issue in the new-cache branch. It will be merged to master branch soon after some testing.

from ejc-sql.

tutysara avatar tutysara commented on July 29, 2024

sure, let me test after office and update

from ejc-sql.

kostafey avatar kostafey commented on July 29, 2024

@tutysara new-cache branch merged to master, so the let's consider issue closed. In the case of any related bugs or ideas, new issues should be created.

from ejc-sql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.