Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTimeout } from 'node:timers/promises'
import { CACHE_MAX_AGE_ONE_DAY } from '#shared/utils/constants'

type GitHubContributorWeek = {
Expand All @@ -12,8 +13,6 @@ type GitHubContributorStats = {
weeks: GitHubContributorWeek[]
}

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

export default defineCachedEventHandler(
async event => {
const owner = getRouterParam(event, 'owner')
Expand Down Expand Up @@ -50,7 +49,7 @@ export default defineCachedEventHandler(

if (status === 202) {
if (attempt === maxAttempts - 1) return []
await sleep(delayMs)
await setTimeout(delayMs)
delayMs = Math.min(delayMs * 2, 16_000)
continue
}
Expand Down
3 changes: 2 additions & 1 deletion server/utils/atproto/lock.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTimeout } from 'node:timers/promises'
import type { RuntimeLock } from '@atproto/oauth-client-node'
import { requestLocalLock } from '@atproto/oauth-client-node'
import { Redis } from '@upstash/redis'
Expand All @@ -22,7 +23,7 @@ function createUpstashLock(redis: Redis): RuntimeLock {

if (!acquired) {
// Another instance holds the lock, wait briefly and retry once
await new Promise(resolve => setTimeout(resolve, 100))
await setTimeout(100)
const retryAcquired = await redis.set(lockKey, lockValue, {
nx: true,
ex: lockTTL,
Expand Down
3 changes: 2 additions & 1 deletion test/unit/server/utils/atproto/lock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTimeout } from 'node:timers/promises'
import { describe, expect, it, vi, beforeEach } from 'vitest'

const mockRedisSet = vi.fn()
Expand Down Expand Up @@ -145,7 +146,7 @@ describe('lock', () => {

const lock = getUpstashLock()
const result = await lock('async-key', async () => {
await new Promise(resolve => setTimeout(resolve, 10))
await setTimeout(10)
return 'async-result'
})

Expand Down
7 changes: 4 additions & 3 deletions test/unit/shared/utils/async.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTimeout } from 'node:timers/promises'
import { describe, expect, it, vi } from 'vitest'
import * as fc from 'fast-check'
import { mapWithConcurrency } from '#shared/utils/async'
Expand All @@ -21,7 +22,7 @@ describe('mapWithConcurrency', () => {
async () => {
concurrent++
maxConcurrent = Math.max(maxConcurrent, concurrent)
await new Promise(resolve => setTimeout(resolve, 10))
await setTimeout(10)
concurrent--
},
3,
Expand Down Expand Up @@ -66,7 +67,7 @@ describe('mapWithConcurrency', () => {
await mapWithConcurrency(items, async () => {
concurrent++
maxConcurrent = Math.max(maxConcurrent, concurrent)
await new Promise(resolve => setTimeout(resolve, 5))
await setTimeout(5)
concurrent--
})

Expand All @@ -84,7 +85,7 @@ describe('mapWithConcurrency', () => {
async () => {
concurrent++
maxConcurrent = Math.max(maxConcurrent, concurrent)
await new Promise(resolve => setTimeout(resolve, 10))
await setTimeout(10)
concurrent--
},
10,
Expand Down
Loading