From: Eric Sherman <hyperbolist@gmail.com>
To: sup-devel <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCHv3] idle and unidle updates
Date: Sat, 23 Jan 2010 00:42:56 -0500 [thread overview]
Message-ID: <1264225074-sup-7366@changeling.local> (raw)
Now handled outside of the main thread to accommodate shelling out to
the editor.
[PATCH] flush index on idle
and
[PATCHv5] [issue14] poll updates accumulate while idle
will still work with this patch.
---
bin/sup | 4 ++++
lib/sup.rb | 2 ++
lib/sup/idle.rb | 42 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 0 deletions(-)
create mode 100644 lib/sup/idle.rb
diff --git a/bin/sup b/bin/sup
index 8bf640b..a5d48f6 100755
--- a/bin/sup
+++ b/bin/sup
@@ -239,6 +239,7 @@ begin
unless $opts[:no_threads]
PollManager.start
+ IdleManager.start
Index.start_lock_update_thread
end
@@ -263,6 +264,8 @@ begin
next
end
+ IdleManager.ping
+
if c == 410
## this is ncurses's way of telling us it's detected a refresh.
## since we have our own sigwinch handler, we don't do anything.
@@ -366,6 +369,7 @@ rescue Exception => e
ensure
unless $opts[:no_threads]
PollManager.stop if PollManager.instantiated?
+ IdleManager.stop if IdleManager.instantiated?
Index.stop_lock_update_thread
end
diff --git a/lib/sup.rb b/lib/sup.rb
index e03a35d..2fbaa02 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -131,6 +131,7 @@ module Redwood
Redwood::CryptoManager.init
Redwood::UndoManager.init
Redwood::SourceManager.init
+ Redwood::IdleManager.init
end
def finish
@@ -341,6 +342,7 @@ require "sup/modes/file-browser-mode"
require "sup/modes/completion-mode"
require "sup/modes/console-mode"
require "sup/sent"
+require "sup/idle"
$:.each do |base|
d = File.join base, "sup/share/modes/"
diff --git a/lib/sup/idle.rb b/lib/sup/idle.rb
new file mode 100644
index 0000000..a3a272f
--- /dev/null
+++ b/lib/sup/idle.rb
@@ -0,0 +1,42 @@
+require 'thread'
+
+module Redwood
+
+class IdleManager
+ include Singleton
+
+ IDLE_THRESHOLD = 60
+
+ def initialize
+ @no_activity_since = Time.now
+ @idle = false
+ @thread = nil
+ end
+
+ def ping
+ if @idle
+ UpdateManager.relay self, :unidle, Time.at(@no_activity_since)
+ @idle = false
+ end
+ @no_activity_since = Time.now
+ end
+
+ def start
+ @thread = Redwood::reporting_thread("checking for idleness") do
+ while true
+ sleep 1
+ if !@idle and Time.now.to_i - @no_activity_since.to_i >= IDLE_THRESHOLD
+ UpdateManager.relay self, :idle, Time.at(@no_activity_since)
+ @idle = true
+ end
+ end
+ end
+ end
+
+ def stop
+ @thread.kill if @thread
+ @thread = nil
+ end
+end
+
+end
--
1.6.6
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
next reply other threads:[~2010-01-23 5:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-23 5:42 Eric Sherman [this message]
2010-02-27 8:06 ` Rich Lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1264225074-sup-7366@changeling.local \
--to=hyperbolist@gmail.com \
--cc=sup-devel@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox