Serverless function improvements (#6769)
- add layer for lambda execution - add layer for local execution - add package resolve for the monaco editor - add route to get installed package for serverless functions - add layer versioning
This commit is contained in:
32
packages/twenty-front/src/hooks/usePreventOverlapCallback.ts
Normal file
32
packages/twenty-front/src/hooks/usePreventOverlapCallback.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useDebouncedCallback } from 'use-debounce';
|
||||
|
||||
export const usePreventOverlapCallback = (
|
||||
callback: () => Promise<void>,
|
||||
wait?: number,
|
||||
) => {
|
||||
const [isRunning, setIsRunning] = useState(false);
|
||||
const [pendingRun, setPendingRun] = useState(false);
|
||||
|
||||
const handleCallback = async () => {
|
||||
if (isRunning) {
|
||||
setPendingRun(true);
|
||||
return;
|
||||
}
|
||||
setIsRunning(true);
|
||||
try {
|
||||
await callback();
|
||||
} finally {
|
||||
setIsRunning(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!isRunning && pendingRun) {
|
||||
setPendingRun(false);
|
||||
callback();
|
||||
}
|
||||
}, [callback, isRunning, pendingRun, setPendingRun]);
|
||||
|
||||
return useDebouncedCallback(handleCallback, wait);
|
||||
};
|
||||
Reference in New Issue
Block a user