Code Monkey home page Code Monkey logo

emacs-deferred's People

Contributors

adrieankhisbe avatar dunn avatar edwardbetts avatar egh avatar hitode909 avatar joddie avatar kiwanami avatar kiyoka avatar kosh04 avatar liblit avatar mar-kolya avatar phst avatar ramnes avatar syohex avatar tarsius avatar tkf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emacs-deferred's Issues

is this the right way to loop downloading?

Hello: The package looks very impressive. It took me a little while to figure out how to loop downloading. The solution below works. Could you comment on whether this is the "right" way to do things? In particular, I was a little surprised that the inner lexical-let seems to be required. Then again, I am not an expert on lexical-let. Any advice would be appreciated. If this, or something close to it, is correct, then it might be useful to add some similar example to the docs, to show that nested chains of deferred:$ work.

(defun download-freenums ()
  (lexical-let ((freenums '("1310.6934"
                            "1310.7131"
                            "1310.8383"
                            "1310.8598"))
                (pos 0)
                (wait-time 50))
    (deferred:$
      (deferred:next 
        (lambda (x) (message (concat "Deferred start; first download: "
                                     (nth pos freenums)))))
      (deferred:nextc it
        (deferred:lambda (x)
          (message "Entering loop, let's see what happens if we nest these...")
          ;; This line was somewhat unexpected
          (lexical-let ((mypos pos))
            (deferred:$
              (deferred:next 
                (lambda (x)
                  (message "Inside inner chain...")))
              (deferred:url-retrieve (concat "http://uk.arxiv.org/e-print/"
                                             (nth mypos freenums)))
              (deferred:nextc it
                (lambda (buf)
                  (with-current-buffer buf
                    (write-file (concat (nth mypos freenums) ".txt")))
                  (kill-buffer buf)))))
          (if (> (length freenums) (incf pos)) ; return nil to stop this loop
              (progn (message
                      (concat "(" (int-to-string pos) "-" (nth pos freenums) 
                              ") Looping..."))
                     (deferred:nextc (deferred:wait wait-time) self)))))
      (deferred:nextc it
        (lambda (x) (message "Deferred end."))))))

Correct way of making parallel http post requests

Hi, I am trying to make a number of concurrent http post requests from inside emacs. The deferred:parallel function seems perfect for this task however I cannot get it to work.

I have an example function with three requests being made bellow. I would like them to all complete asynchronously in parallel and then return the result as a list in the deferred:nextc function so I can operate on them.

(defun my-deferred-func ()
  (let ((lk ))
   (deferred:$
     (deferred:parallel
       (request (format "http://localhost:%s" tern-known-port)
                :type "POST"
                :parser 'json-read
                :success (function* (lambda (&key data &allow-other-keys)
                                      (push  (cdr (car data)) lk)))
                :data
                (format "{\"query\":{\"end\":%s,\"file\":\"%s\",\"type\":\"type\",\"preferFunction\":true}}"
                        196
                        (buffer-file-name)
                        )
                :sync nil)
       (request (format "http://localhost:%s" tern-known-port)
                :type "POST"
                :parser 'json-read
                :success (function* (lambda (&key data &allow-other-keys)
                                      (push  (cdr (car data)) lk)))
                :data
                (format "{\"query\":{\"end\":%s,\"file\":\"%s\",\"type\":\"type\",\"preferFunction\":true}}"
                        196
                        (buffer-file-name)
                        )
                :sync nil)
       (request (format "http://localhost:%s" tern-known-port)
                :type "POST"
                :parser 'json-read
                :success (function* (lambda (&key data &allow-other-keys)
                                      (push  (cdr (car data)) lk)))
                :data
                (format "{\"query\":{\"end\":%s,\"file\":\"%s\",\"type\":\"type\",\"preferFunction\":true}}"
                        196
                        (buffer-file-name)
                        )
                :sync nil)
       )
     (deferred:nextc it (lambda (args) args))
     )))

The above requests make a simple post request to the ternjs server.

Any guidance on using deferred:parallel? I have also seen the deferred:url-post but having trouble wrapping my head around that function too.

Wish: More flexible deferred:url-post function.

This is an excellent library.
When I'm trying to create a POST command with raw format in the data field. It won't let me do this because following code in the deferred:url-post:

(url-request-data (deferred:url-param-serialize params))

e.g. I need to fill in the data field with a JSON object.

So I'm currently using deferred:url-retrieve to complete my mission.
It would be very nice if the API is more generic. :D

Fix tests

The test codes test-deferred.el and test-concurrent.el fail.
They should be fixed as soon as possible.

debian warning during the emacs-deferred installation

Hello like for ctables, I get this during the installation

Install emacs-deferred-el for emacs23
install/deferred: Handling install for emacsen flavor emacs23

In deferred:earlier-main:
deferred.el:655:40:Warning: value returned from (length (symbol-value G20439))
is unused
deferred.el:655:40:Warning: value returned from (symbol-value G20441) is
unused
deferred.el:655:40:Warning: value returned from (length (symbol-value G20439))
is unused
deferred.el:655:40:Warning: value returned from (symbol-value G20441) is
unused
Wrote /usr/share/emacs23/site-lisp/deferred/deferred.elc
Wrote /usr/share/emacs23/site-lisp/deferred/concurrent.elc
Install emacs-deferred-el for emacs24
install/deferred: Handling install for emacsen flavor emacs24

In deferred:earlier-main:
deferred.el:655:40:Warning: value returned from (length (symbol-value G20439))
is unused
deferred.el:655:40:Warning: value returned from (symbol-value G20441) is
unused

cheers

Frederic

define 'cancel'

Currently, the documentation doesn't clearly indicate what "cancelling" involves. It probably wouldn't hurt to be explicit what does and what doesn't occur with cancelling. For example, a modified version of an example from the documentation reveals that cancelling does not imply that things halt or are terminated in any way (the WAIT continues and the subsequent NEXTC does its thing as well):

(deferred:$
  (deferred:earlier
    (deferred:process "sh" "-c" "sleep 3 | echo 'hello!'")
    (deferred:$
      (deferred:wait 4000) ; timeout msec
      (deferred:nextc it (message "canceled!"))))
  (deferred:nextc it
    (lambda (x) (insert x))))

ドキュメント移行に関する議論など

#16 に関する議論ですが、 twitter でやるより日本語でも良いから issue にでやったほうが便利じゃないかと思ったのでこっちに作ってみましたがどうでしょう? twitter のほうが良いですか?

放っておくとマージが辛くなりそうなので、決めたほうが良いと思うこと (後の方に書いてますが、 sphinxcontrib-emacs の現状にかなり左右されると思います):

  1. #16 のマージを sphinxcontrib-emacs のリリースまで待つかどうか。
  2. もしリリースまで待つなら、 docstring の移行を #16 でやるかどうか。 docstring 以外の移行を #16 でしてしまって、さっさとマージするのもありだと思います。 API のページ (autodoc 経由で作られたページ) は「実験的に公開してるのでフォーマット崩れても気にしないでね」みたいな態度もありかもしれません。
  3. もしリリースまで待た ない で docstring の移行を #16 でやるなら、 docstring のテンプレートをどうするか。 ReST にどれくらい依存するか? 依存するにしても色々書き方あるけれどどうするか?

sphinxcontrib-emacs の現状なんですが、
ttps://github.com/flycheck/sphinxcontrib-emacs/issues/12 (←2chっぽい)
で議論した感じだと、「ReST マークアップに *Help* を組み合わせる案、良いと思ったんだけど色々問題出てきてやっぱやめようか迷ってる。ReSTの処理系を色々弄って実験してる最中だし忙しいし、リリースまだまだ遠いかも。」みたいな感じらしいです。

ad147a31814a40 で提案した docstring のテンプレートは ReST にかなり依存した書き方になっているんで、 sphinxcontrib-emacs が 「ReST やっぱり辞める。ごめんね。」ってなった場合に、大規模な docstring のスタイル変更が必要になります。doc/requirements.txt で書いてあるように github 経由で必要な sphix module をインストールしているんですが、最悪リビジョンを指定して使い続けることもできるんで、このまま移行してしまうという方法も一応考えられます。 docstring が充実するという意味では、 Emacs hacker な人たち的にはプラスだと思いますが、二度手間になる可能性があるのを考えるとあまり推してしまってはまずいかな、とも思います。

私の提案としては、こんな感じです(楽さを重視):

  1. #16 は docstring 以外のドキュメントの移行が終了次第マージ。
  2. リリース待たないで「実験的な公開」ってことにしてAPIドキュメントも公開。ただし、 docstring の README からの移行は(既にされたものを除いては)しない。
  3. docstring テンプレは sphinxcontrib-emacs のリリース後に考える。
  4. @kiwanami さんが cacoo か何かでコールバックチェーンを図解する的なワクワクする図を書いてそれをドキュメントのトップに置く→ハッカーニュースとかに投稿する→deferred.el 大勝利

Support for running deferred object synchronously?

Is it OK to use deferred:sync! in normal code, i.e. outside testing and debugging? Will that function continue to be supported in the future?

I've got a situation where I've written some code using deferred. It's part of the emacs-ycmd project, for communicating with a completion server. However, the completion frameworks I want to integrate with (company, auto-complete, etc.) operate in a very synchronous way. It seems that the simplest way to integrate my asynchronous, deferred-based code with their frameworks is to use something like deferred:sync!.

So, is it safe for me to use deferred:sync!? It seems to do exactly what I need.

If it's not OK to use deferred:sync!, is there an alternative? The only other option I can see is to have a synchronous and asyncronous version of my HTTP request code, and that seems silly.

[Suggestion] more ergonomic anamorphic features

What do you think about defining a set of anamorphic versions of the functions, like this:

(defmacro deferred::nextc (d &rest body) ;; the prefix could be different.
  `(deferred:nextc ,d (lambda (result)
                        ,@body)))

Here it is how the readme example will look like(using dash's ->).

(-> (deferred::next (message "deferred start"))
    (deferred::nextc 
      (message "chain 1")
      1)
    (deferred::nextc (message "chain 2 : %s" result))
    (deferred::nextc (read-minibuffer "Input a number: "))
    (deferred::nextc (message "Got the number : %i" result))
    (deferred::error (message "Wrong input : %s" error)))

Deferred getting stuck on tramp for whatever reason

This issue is coming up in a downstream usage, via company-jedi, aka jedi (python auto complete in emacs).

Used emacs + TRAMP to work on a ros project

deferred error : (user-error "Not a Tramp file name: \"/Workspace [bazel]: /home/edgar/code/ros
Rosbag: Saving bag file LOCALLY to /home/edgar/data/ext_dsshare/emacs/site-lisp/\"")

This happening even when I'm not over tramp, now directly working on the machine.

default-directory for process functions are unpredictable

(let ((default-directory "/"))
  (deferred:nextc (deferred:process "pwd") 'message)
  (let ((default-directory "~/"))
    (dotimes (_ 3)
      (sleep-for 0.1))))  ; prints $HOME ("/" is expected).

default-directory はサブプロセスの $PWD を決めるのに使われますが、 deferred の process 系関数だと、それを決める方法が無いようです。

Is there a way to extract the stderr of a process that returns a non-zero status code?

I'm writing an emacs mode that relies on a parser that returns a non-zero status code if there are certain types of parsing errors. I'd like to extract the stderr output in these cases, however the best I've been able to figure out how to do is to extract the text that also specifies that there has been an error within the deferred library.

Looking in the source code, it looks like the message is immediately run through a format function. Is there a way to get the stderr output without having to parse this string?

Most robust way to "finally" processing?

The documentation warns that sometimes a "finally" block may not be executed due to asynchrony. If I have some clean-up code that needs to be run no matter how a deferred chain terminates, what's the best, most robust way to do that? I worry about implementing cleanup code that silently gets ignored sometimes.

Skip deferred:wait-idle delay while waiting for previously deferred task to complete?

Hi,

I'm working on making a CPU-intensive function called from the modeline loop asynchronous, and am using a simple boolean var as a lock to skip body of a deferred:nextc it function when the lock is active. Unfortunately deferred:wait-idle unconditionally blocks execution of the deferred task chain. Would it be possible useful to add a third argument to its function definition? Something like a bool, that if nil will not block while waiting for the idle timer to expire (eg: skip the timer if nil). The form would become deferred:wait-idle (msec) (optional-boolean-lock).

I'm using a simple:

(deferred:$
  (deferred:wait-idle idle-wait-value)
  (deferred:next it (lambda (elapsed) set-lock-and-do-slow-CPU-intensive-stuff))
  (deferred:next it (lambda (result) format-result-as-a-string-and-set-a-var-and-unset-lock)))

The buffer-local var set in the 3rd task is evaluated in the modeline loop. The 3rd task also unsets the lock. The specific issue I'm experiencing is that the unconditional wait-idle introduces a minimum latency of 2x the idle-wait-value. In my case it might be possible to merge 2nd and 3rd tasks, but I believe other people would find it useful to be able to conditionally skip the wait-idle task, thus eliminating the guarantied latency of 1x idle-wait-value.

Thank you for maintaining emacs-deferred!
Nicholas

Perhaps tag a release?

It's been 2.5 years since the last release, and a lot of stuff has happened. It would be nice if there were an actual number authors could use for dependencies, rather than having to depend on the melpa release.

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.