POO Library

$pub.periodic.standard

This object is the parent of any common object which needs to execute a task periodically. It contains commands for turning the periodic task on and off, and includes error trapping to make it easier to notice when there is a problem. It is highly recommended that all POO servers include this object, as it seems likely that many POO coders will assume it exists.
@create $thing as standard
@set standard.f = 1
@set standard.interval = 300

@newfunc standard.update(self)
if time() - self.lastTime < self.interval: return
self.lastTime = time()
try: self.periodicTask()
except:
	self.owner.tell("Bug in " + self.name + \
		".periodicTask().  Updates stopped.")
	self.wantsUpdates = 0
.x

@newfunc standard.checkPerm(self)
if user != self and user != self.owner and not user.wizard:
	print self.name + " belongs to " + self.owner.name + "."
	return 0
return 1
.x

@newfunc standard.start(self)
if not self.checkPerm(): return
self.wantsUpdates = 1
self.lastTime = time() - self.interval
print self.name, "started."
if user != self.owner:
	self.owner.tell( user.name + " has started " + self.name + "." )
.x
@cmd standard.start <this> calls start()

@newfunc standard.stop(self)
if not self.checkPerm(): return
self.wantsUpdates = 0
print self.name, "stopped."
if user != self.owner:
	self.owner.tell( user.name + " has stopped " + self.name + "." )
.x
@cmd standard.stop <this> calls stop()

@newfunc standard.periodicTask(self)
self.owner.tell( self.name + " has received a call to periodicTask()." )
.x

beam standard to $pub.periodic

Usage

To create your own periodically updated object, derive it from this one:
@create $pub.periodic.standard as myBeeper
You can then set the timing interval by setting your object's .interval property in seconds (it defaults to 300, i.e., 5 minutes).

Start the periodic updates with a command such as start myBeeper, and stop it similarly (stop myBeeper). While it is running, you (as the owner of the object) will receive a message every time its periodic task is executed.

To make your object do something more useful, override the .periodicTask function, like this:

@newfunc myBeeper.periodicTask(self)
self.location.broadcast("You heer a beep.")
.x


http://www.strout.net/python/poo/lib/periodic.standard.html
Last Updated: 10/06/97 . . . . . . Joe Strout