Permalink
Browse files

Fixing race condition, where we try and process output that hasn't

arrived yet.  The answer you were looking for was "process filters".
They hid that pretty well (ok, I just didn't read carefully enough).
  • Loading branch information...
1 parent 30c0ec0 commit 1b501c4676d1912246e24eba78de48827eaccfb1 @markhepburn markhepburn committed Apr 6, 2011
Showing with 13 additions and 8 deletions.
  1. +13 −8 mplayer-minor-mode.el
View
@@ -127,14 +127,19 @@
(defun mplayer-insert-timestamp ()
(interactive)
(let (time)
- (mplayer--send "get_time_pos")
- (with-current-buffer mplayer-process-buffer
- (goto-char (point-max))
- (search-backward-regexp "^ANS_TIME_POSITION=\\(.*\\)$" 0 t)
- (setq time (match-string 1)))
- (if time
- (insert (mplayer--format-time time))
- (message "MPlayer: couldn't detect current time."))))
+ (set-process-filter
+ mplayer-process
+ ;; wait for output, process, and remove filter:
+ (lambda (process output)
+ (message "process: %s output: %s" process output)
+ (string-match "^ANS_TIME_POSITION=\\(.*\\)$" output)
+ (setq time (match-string 1 output))
+ (if time
+ (insert (mplayer--format-time time))
+ (message "MPlayer: couldn't detect current time."))
+ (set-process-filter mplayer-process nil)))
+ ;; Then send the command:
+ (mplayer--send "get_time_pos")))
(defun mplayer-quit-mplayer ()
(interactive)

0 comments on commit 1b501c4

Please sign in to comment.