<HEAD><TITLE>discuss@charon: [620] in "Coldmud discussion meeting"</TITLE>
<H1>[620] in Coldmud discussion meeting</H1></HEAD>
<A HREF="/"><IMG SRC="/i-d.gif" ALT="root"></A>
<A HREF="?620"><IMG SRC="/i-back.gif" ALT="meeting"></A>
<A HREF="/help.html"><IMG SRC="/i-help.gif" ALT="help"></A>
<A HREF="1"><IMG SRC="/i-first.gif" ALT="first"></A>
<A HREF="619"><IMG SRC="/i-fref.gif" ALT="first in chain"></A>
<A HREF="619"><IMG SRC="/i-pref.gif" ALT="previous in chain"></A>
<A HREF="619"><IMG SRC="/i-prev.gif" ALT="previous"></A>
<A HREF="621"><IMG SRC="/i-next.gif" ALT="next"></A>
<IMG SRC="/n-nref.gif" ALT="">
<IMG SRC="/n-lref.gif" ALT="">
<A HREF="1641"><IMG SRC="/i-last.gif" ALT="last"></A>
<HR><H2>Returned mail: User unknown</H2>
<H3>daemon@ATHENA.MIT.EDU (Sat Dec 17 22:48:47 1994
)</H3>
<PRE>
Date: Sat, 17 Dec 1994 18:17:59 -0800
From: Mailer-Daemon@netcom.com (Mail Delivery Subsystem)
To: jeffpk@netcom.com

The original message was received at Sat, 17 Dec 1994 18:17:57 -0800
from jeffpk@localhost

   ----- The following addresses had delivery problems -----
coldtuff@mit.edu  (unrecoverable error)

   ----- Transcript of session follows -----
... while talking to pacific-carrier-annex.mit.edu.:
&gt;&gt;&gt; RCPT To:&lt;coldtuff@mit.edu&gt;
&lt;&lt;&lt; 550 &lt;coldtuff@mit.edu&gt;... User unknown: Bad file number
550 coldtuff@mit.edu... User unknown

   ----- Original message follows -----
Return-Path: &lt;jeffpk&gt;
Received: by netcom9.netcom.com (8.6.9/Netcom)
	id SAA26252; Sat, 17 Dec 1994 18:17:57 -0800
From: jeffpk (Jeff Kesselman)
Message-Id: &lt;199412180217.SAA26252@netcom9.netcom.com&gt;
Subject: A timer object.
To: coldtuff@mit.edu
Date: Sat, 17 Dec 1994 18:17:57 -0800 (PST)
X-Mailer: ELM [version 2.4 PL23]
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 2670      

I've written a first pass at a simpel timer object.  The idea was a 
minimal suite of functionality to allow 'system independance' of functions
that need a timed call back.  

Its small and should be pretty self-explanatory.  It supports two kinds 
of call backs, a one-shot (called an alarm) and a periodic (called a clock.)

How close the timing is to the timign asked for is a function of the 
period of the heartbeat.  You need to put a call to $timer.pulse() in the 
system heartbeat function.

Jeff Kesselman
---------------------------------------------------------------------
// OBJECT: timer
// PURPOSE:  Provides 2 kinds of time based callbacks.
//		alarms: an alarm provides a single call back in n seconds
//              clocks: a clock provides a repeating call back every n seconds
// AUTHOR:  Jeffrey P. Kesselman


parent $utilities
object $timer

var $root child_index 0
var $root owners [$timer]
var $root fertile 0
var $root inited 1
var $root owned [$timer]
var $root manager $timer
var $root writable [$timer]
var $root readable ['parameters, 'methods, 'code]
var $root dbref 'timer
var $timer timerCBs [] // [ [time,obj,function,args,reset_value,id]]


method init_timer
.

method pulse
	var cb,newlist, curr_time, temp;

	curr_time = time();	
	newlist = timerCBs;
	for cb in (timerCBs){
	  if ( curr_time &gt; cb[1]){
		cb[2].(cb[3])(@cb[4]);
	        temp = cb;
		newlist = setremove(newlist,cb);
		if (temp[5] != 0){
		   newlist = [@newlist,[temp[5]+curr_time,temp[2],temp[3],
			      temp[4],temp[5],temp[6]]];
		}
	  } 
	}
        timerCBs = newlist;
.

method add_alarm
	arg obj, func, args, seconds,id;	

	if (type(seconds) != 'integer)
	   throw(~type, "Passed seconds not an integer");
	if (type(args) != 'list)
	   throw(~type, "Passed args not a list");
	if (type(obj) != 'dbref)
	   throw(~type, "Passed object not a dbref.");
	if (type(func) != 'symbol)
	   throw(~type, "Passed functio not a symbol.");
	timerCBs = [@timerCBs,[time()+seconds,obj,func,args,0,id]]; 
.

method add_clock
	arg obj, func, args, seconds, id;	

	if (type(seconds) != 'integer)
	   throw(~type, "Passed seconds not an integer");
	if (type(args) != 'list)
	   throw(~type, "Passed args not a list");
	if (type(obj) != 'dbref)
	   throw(~type, "Passed object not a dbref.");
	if (type(func) != 'symbol){
	   (&gt; $user_catseye.tell("func type = "+tostr(type(func))) &lt;);
	   throw(~type, "Passed function not a symbol.");
        }
	timerCBs = [@timerCBs,[time()+seconds,obj,func,args,seconds,id]]; 
.

method remove
	arg id;
	var temp;

	for temp in (timerCBs)
		if (temp[6] == id) {
		   timerCBs = setremove(timerCBs,temp);
		   return(1);
		}
	return(0);
.




</PRE>
