├── holler.js ├── LICENSE └── README.md /holler.js: -------------------------------------------------------------------------------- 1 | function holler( fn, interval ) { 2 | interval = interval || 1000; 3 | (function holl(){ 4 | fn(); 5 | setTimeout( holl, interval ); 6 | })(); 7 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Oyedele Hammed Horlah 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # holler.js 2 | 144-bytes lightweight JavaScript polling library! 3 | 4 | > This library can be used to setup a run function in specified intervals that can also be used for polling the server for new data. one of the advantages of this library is to avoid the evil behaviour of `setInterval` which is a function interval don't wait for the former function to finish before starting which results in bunch of functions that has not been executed. 5 | ## Use-cases 6 | - AJAX to pull data repeatedly 7 | - Run a function in intervals 8 | etc. 9 | 10 | ## API 11 | ```js 12 | holler( func, intervalMs=1000 ); 13 | ``` 14 | > `func` is the function to run. 15 | 16 | > `intervalMs` is the intervals to run `func` in milliseconds, **defaults: `1000`**. 17 | 18 | ## Example 19 | ```js 20 | holler( function(){ 21 | fetch( 'http://www.awesome-site.com/api/feeds', myOptions ) 22 | .then(function( data ) { 23 | // Here you get the data to modify as you please 24 | }) 25 | .catch(function( error ) { 26 | // If there is any error you will catch them here 27 | }); 28 | } , 2000 ); // 2000ms = 2 seconds 29 | ``` 30 | 31 | Thanks - [Oyedele Hammed](https://devhammed.github.io) 32 | --------------------------------------------------------------------------------