Mercurial > hg > ishara
view sched/sched.m @ 0:672052bd81f8
Initial partial import.
author | samer |
---|---|
date | Wed, 19 Dec 2012 22:38:28 +0000 |
parents | |
children |
line wrap: on
line source
function x=sched(f,dt,nout) % sched - execute action after delay % % sched :: % (unit -> action (A1,...,AN)) ~'action with N return values', % nonneg ~'delay in seconds', % M:natural ~'number of output arguments to collect' % -> unit -> action (A1,...,AM). % % After use, timer is marked for deletion but you must call % timer_gc to actually delete it. if nargin<3, nout=0; end rc=cell(1,nout); tim=timer('TimerFcn',@(t,e)timfn,'StopFcn',@stopfn,'StartDelay',dt); start(tim); x=@()collect(); function timfn, [rc{:}]=f(); end function stopfn(t,e), timer_release(t); end function varargout=collect(), if isvalid(tim), wait(tim); end varargout=rc; end end