timers#setTimeout TypeScript Examples
The following examples show how to use
timers#setTimeout.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: save-course.route.ts From reactive-angular-course with MIT License | 6 votes |
export function saveCourse(req: Request, res: Response) {
/*
console.log("ERROR saving course!");
res.sendStatus(500);
return;
*/
const id = req.params["id"],
changes = req.body;
console.log("Saving course changes", id, JSON.stringify(changes));
const newCourse = {
...COURSES[id],
...changes
};
COURSES[id] = newCourse;
console.log("new course version", newCourse);
setTimeout(() => {
res.status(200).json(COURSES[id]);
}, 2000);
}
Example #2
Source File: search-lessons.route.ts From reactive-angular-course with MIT License | 6 votes |
export function searchLessons(req: Request, res: Response) {
const queryParams = req.query;
const courseId = queryParams.courseId,
filter = queryParams.filter || '',
sortOrder = queryParams.sortOrder || 'asc',
pageNumber = parseInt(queryParams.pageNumber) || 0,
pageSize = parseInt(queryParams.pageSize) || 3;
let lessons;
if (courseId) {
lessons = Object.values(LESSONS).filter(lesson => lesson.courseId == courseId).sort((l1, l2) => l1.id - l2.id);
}
else {
lessons = Object.values(LESSONS);
}
if (filter) {
lessons = lessons.filter(lesson => lesson.description.trim().toLowerCase().search(filter.toLowerCase()) >= 0);
}
if (sortOrder == "desc") {
lessons = lessons.reverse();
}
const initialPos = pageNumber * pageSize;
const lessonsPage = lessons.slice(initialPos, initialPos + pageSize);
setTimeout(() => {
res.status(200).json({payload: lessonsPage});
},1000);
}
Example #3
Source File: AddressInput.tsx From mStable-apps with GNU Lesser General Public License v3.0 | 6 votes |
AddressInput: FC<Props> = ({ onClick, title, className }) => {
const inputValue = useRef<string | undefined>()
const [invalid, setInvalid] = useState(false)
const handleChange = useCallback<ChangeEventHandler<HTMLInputElement>>(event => {
inputValue.current = event.target.value
}, [])
const handleClick = useCallback(() => {
const address = inputValue.current ?? ''
if (!isAddress(address)) {
setInvalid(true)
setTimeout(() => setInvalid(false), 200)
return
}
onClick(address)
}, [onClick])
return (
<Container className={className}>
<CSSTransition in={invalid} timeout={200}>
{className => <StyledInput className={className} placeholder="0x0000…0000" onChange={handleChange} />}
</CSSTransition>
<Button onClick={handleClick}>{title}</Button>
</Container>
)
}
Example #4
Source File: action.ts From actions-clever-cloud with MIT License | 5 votes |
export default async function run({
token,
secret,
appID,
alias,
cleverCLI,
timeout,
extraEnv = {}
}: Arguments): Promise<void> {
try {
await checkForShallowCopy()
core.debug(`Clever CLI path: ${cleverCLI}`)
// Authenticate (this will only store the credentials at a known location)
await exec(cleverCLI, ['login', '--token', token, '--secret', secret])
// There is an issue when there is a .clever.json file present
// and only the appID is passed: link will work, but deploy will need
// an alias to know which app to publish. In this case, we set the alias
// to the appID, and the alias argument is ignored if also specified.
if (appID) {
core.debug(`Linking ${appID}`)
await exec(cleverCLI, ['link', appID, '--alias', appID])
alias = appID
}
// If there are environment variables to pass to the application,
// set them before deployment so the new instance can use them.
for (const envName of Object.keys(extraEnv)) {
const args = ['env', 'set']
if (alias) {
args.push('--alias', alias)
}
args.push(envName, extraEnv[envName])
await exec(cleverCLI, args)
}
const args = ['deploy']
if (appID) {
args.push('--alias', appID)
} else if (alias) {
args.push('--alias', alias)
}
if (timeout) {
let timeoutID: NodeJS.Timeout | undefined
let timedOut = false
const timeoutPromise = new Promise<void>(resolve => {
timeoutID = setTimeout(() => {
timedOut = true
resolve()
}, timeout)
})
const result = await Promise.race([exec(cleverCLI, args), timeoutPromise])
if (timeoutID) {
clearTimeout(timeoutID)
}
if (timedOut) {
core.info('Deployment timed out, moving on with workflow run')
}
core.info(`result: ${result}`)
if (typeof result === 'number' && result !== 0) {
throw new Error(`Deployment failed with code ${result}`)
}
} else {
const code = await exec(cleverCLI, args)
core.info(`code: ${code}`)
if (code !== 0) {
throw new Error(`Deployment failed with code ${code}`)
}
}
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message)
} else {
core.setFailed(String(error))
}
}
}
Example #5
Source File: main.tsx From covid_dashboard with MIT License | 5 votes |
private handleChangeHotRegion(region: string) {
this.setState({hotRegion: region});
setTimeout(() => {this.setState({hotRegion: ""})}, 1000);
}
Example #6
Source File: update_lock.ts From SpaceEye with MIT License | 5 votes |
private constructor(initiator: Initiator) {
this.initiator = initiator
this.downloadCancelTokens = new Set()
this.lockTimeout = setTimeout(() => {
this.invalidate()
}, LOCK_TIMEOUT)
}
Example #7
Source File: app.ts From ken-axios with MIT License | 5 votes |
setTimeout(() => {
// source.cancel('用户手动取消')
}, 100)
Example #8
Source File: app.ts From ken-axios with MIT License | 5 votes |
setTimeout(() => {
source2.cancel("用户手动取消")
}, 200);
Example #9
Source File: app.ts From ken-axios with MIT License | 5 votes |
setTimeout(() => {
cancel("用户手动取消")
}, 500);