Google Groups Home Help | Sign in
Function.intervalize released.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
gugod  
View profile
 More options Jun 8 2007, 9:14 am
From: gugod <gugod...@gmail.com>
Date: Fri, 08 Jun 2007 13:14:15 -0000
Local: Fri, Jun 8 2007 9:14 am
Subject: Function.intervalize released.
Hi, all.

Function.intervalize 已經釋出於 JSAN。這個模組是為了解決此項特定的問題:函式可能常常會在一段很短暫的時間內被大量呼叫
好幾次,使得 CPU 使用率突然飆高。比如說,如果我有一函式 notify():

function notify(msg) {
  // 在畫面左下角顯示一小段訊息

}

其達成功能,是在畫面某處顯示訊息(如 MSN 的上線通知),並於一小段時間後消失。基於 Javascript 多頭執行的特性,這個函式可能會在
多處被呼叫,甚至,有可能在同一秒內被呼叫數十次(MSN 的聯絡人的確也有可能突然在同一秒內有數人同時上線)。那麼,可以想像的是,顯示的提醒訊息
將會突然蓋滿畫面而失去其原本的功用。

此時的解決辨法,便是固定讓它每秒出現一則就好。使用 Function.intervallize 的話,則改用以下的寫法便可:

var notify = (function(msg) {
  // 在畫面左下角顯示一小段訊息

}).intervalize(1000);

如此一來,即便是連續呼叫 notify 五次:

notify("foo");
notify("bar");
notify("baz");
notify("foobar");
notify("foobaz");

也不會一次出現五則,而是在五秒鐘內,每秒出現一則。intervalize() 方法的參數便是區間的毫秒數。在此時間區間之內,原函式的保證只會進
行一次。

Cheers,
Kang-min Liu


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gugod  
View profile
 More options Jun 8 2007, 4:12 pm
From: gugod <gugod...@gmail.com>
Date: Fri, 08 Jun 2007 20:12:44 -0000
Local: Fri, Jun 8 2007 4:12 pm
Subject: Re: Function.intervalize released.
JSAN 方面的 index 更新實在不令人放心。因此先釋出於:

http://dl.handlino.com/Function-intervalize-0.01.tar.gz

讓大家可以抓回去看看。

Cheers,
Kang-min Liu


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google