% sched_abs- Use one-shot timer to schedule action
%
% sched_abs:: timer, time, (timer, timer_event => void) => void.
%
% Can only be used on a stopped timer, whereas callback executes with
% a running timer.

function x=sched_abs(f,T,nout)
	if nargin<3, nout=nargout(f); end
	rc=cell(1,nout);
	tim=timer('TimerFcn',@(t,e)timfn,'StopFcn',@stopfn,'StartDelay',quant(0.001,T-nows));
	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
