$timeout function implementation