phpjs
Version:
57 lines (47 loc) • 2.23 kB
Markdown
---
layout: page
title: "JavaScript time_sleep_until function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/time_sleep_until:564
- /functions/view/time_sleep_until
- /functions/view/564
- /functions/time_sleep_until:564
- /functions/564
---
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's time_sleep_until
{% codeblock misc/time_sleep_until.js lang:js https://raw.github.com/kvz/phpjs/master/functions/misc/time_sleep_until.js raw on github %}
function time_sleep_until (timestamp) {
// From: http://phpjs.org/functions
// + original by: Brett Zamir (http://brett-zamir.me)
// % note: For study purposes. Current implementation could lock up the user's browser.
// % note: Expects a timestamp in seconds, so DO NOT pass in a JavaScript timestamp which are in milliseconds (e.g., new Date()) or otherwise the function will lock up the browser 1000 times longer than probably intended.
// % note: Consider using setTimeout() instead.
// * example 1: time_sleep_until(1233146501) // delays until the time indicated by the given timestamp is reached
// * returns 1: true
while (new Date() < timestamp * 1000) {}
return true;
}
{% endcodeblock %}
- [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/misc/time_sleep_until.js)
Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are
the closest match to this hashtable-like data structure.
Please also note that php.js offers community built functions and goes by the
[McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online
functions that are far from perfect, in the hopes to spark better contributions.
Do you have one? Then please just:
- [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/misc/time_sleep_until.js)
### Example 1
This code
{% codeblock lang:js example %}
time_sleep_until(1233146501) // delays until the time indicated by the given timestamp is reached
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
true
{% endcodeblock %}
### Other PHP functions in the misc extension
{% render_partial _includes/custom/misc.html %}