Skip to main content

setTimeout

Function

Sets a timeout to call the provided callback after the specified number of milliseconds.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

setTimeout(code, delay): number

Sets a timeout to call the provided callback after the specified number of milliseconds. The callback is invoked on the scripting thread once the deadline has passed. Use clearTimeout with the returned TimeoutID to cancel a pending timeout before it fires.

Parameters

ParameterType
code() => void
delaynumber

Returns

number

TimeoutID that can be used to clear the timeout.

Example

const timeoutId = setTimeout(function() {
print("One second has passed.");
}, 1000);

// Cancel the timeout before it fires:
clearTimeout(timeoutId);