generated from VLADIMIR/template_frontend
add pooling for game
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { ref, onMounted, onUnmounted } from 'vue';
|
||||
|
||||
export function useSimplePolling(callback: () => void, interval = 5000) {
|
||||
const isActive = ref(true);
|
||||
let timerId: number | null = null;
|
||||
|
||||
const start = () => {
|
||||
isActive.value = true;
|
||||
callback();
|
||||
timerId = window.setInterval(callback, interval);
|
||||
};
|
||||
|
||||
const stop = () => {
|
||||
isActive.value = false;
|
||||
if (timerId) {
|
||||
clearInterval(timerId);
|
||||
timerId = null;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(start);
|
||||
onUnmounted(stop);
|
||||
|
||||
return { isActive, start, stop };
|
||||
}
|
||||
Reference in New Issue
Block a user