From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.213.28.69 with SMTP id l5cs6094ebc; Fri, 22 Jan 2010 21:43:06 -0800 (PST) Received: by 10.224.93.201 with SMTP id w9mr2567178qam.191.1264225385554; Fri, 22 Jan 2010 21:43:05 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 7si6564233qwf.34.2010.01.22.21.43.05; Fri, 22 Jan 2010 21:43:05 -0800 (PST) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org; dkim=neutral (body hash did not verify) header.i=@gmail.com Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id C7D3618582EE; Sat, 23 Jan 2010 00:43:04 -0500 (EST) Received: from mail-iw0-f186.google.com (mail-iw0-f186.google.com [209.85.223.186]) by rubyforge.org (Postfix) with ESMTP id 0415F18582CE for ; Sat, 23 Jan 2010 00:42:59 -0500 (EST) Received: by iwn16 with SMTP id 16so745225iwn.33 for ; Fri, 22 Jan 2010 21:42:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:content-type:subject:from:to :date:message-id:user-agent:content-transfer-encoding; bh=Xii9lnXsyO3L8aOic0nkZKy0Namr5iqMmJa+DLV9S5Y=; b=CaJEk2JIMX1ow10zGFwRJ2ldL9pMld+zx3cPw9BsVu3Xlzp0A5fZVCj/QKkboZi3k/ fRq788Achg+tUFv3CR6uH68OE7w5PSzPs0jm8ALjIovkJy08p6hdZYpY8RAyKLQ5SOEz 0oxQXsyqFQDnNyGtml5w3s44HMD7qrsogP9Nw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=content-type:subject:from:to:date:message-id:user-agent :content-transfer-encoding; b=bB93RG4Kbv83jX3DIspJDKxckNUvkTGwkXnJscWcwOg+NPolAtm7e9YDf1IuSW7y1h gkvZDq/p2U6Ah8EVKY1/Fb7zoAOINjZhkj2AmOn62MIrXsYuAfZ29EF59zHIgv+LhpMN VYmCCxE+B3OPPsySRi4G/6vOEzoDFFI4ZqV9M= Received: by 10.231.146.2 with SMTP id f2mr6342523ibv.23.1264225379536; Fri, 22 Jan 2010 21:42:59 -0800 (PST) Received: from localhost (c-76-98-110-216.hsd1.nj.comcast.net [76.98.110.216]) by mx.google.com with ESMTPS id 20sm2391860iwn.9.2010.01.22.21.42.57 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 22 Jan 2010 21:42:58 -0800 (PST) From: Eric Sherman To: sup-devel Date: Sat, 23 Jan 2010 00:42:56 -0500 Message-Id: <1264225074-sup-7366@changeling.local> User-Agent: Sup/git Subject: [sup-devel] [PATCHv3] idle and unidle updates X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org 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