Skip to content

Instantly share code, notes, and snippets.

@fvdm
Last active February 17, 2024 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fvdm/23a77945799d204512877caf87aee9a2 to your computer and use it in GitHub Desktop.
Save fvdm/23a77945799d204512877caf87aee9a2 to your computer and use it in GitHub Desktop.
HomeyScript to stall the flow a number of minutes, seconds or millieconds (default)
/**
* HomeyScript to stall the flow a number of [m]inutes, [s]econds or [m]illi[s]econds (default)
*
* @example 2 -> waiting 2ms
* @example 2m -> waiting 2 min
* @example 2s -> waiting 2 seconds
*
* @see {@link https://gist.github.com/fvdm/23a77945799d204512877caf87aee9a2}
*/
let ms = args[0];
const regex = /^(?<amount>\d+) *(?<unit>ms|m|s)$/;
const match = regex.exec( ms );
const units = {
'ms': 1,
's': 1000,
'm': 60000,
};
if ( match ) {
ms = match.groups.amount * units[match.groups.unit];
}
ms = parseInt( ms, 10 ) || 1000;
ms = ms < 0 ? 0 : ms;
await wait( ms );
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment