That would depend on the detailed requirement, but you might want to look at:
https://wiki.asterisk.org/wiki/display/AST/Function_TIMEOUT