Skip to content

Commit

Permalink
refactor: use abortsignal
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Goller <[email protected]>
  • Loading branch information
goller committed Apr 26, 2024
1 parent 94459d6 commit 77717c5
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/utils/fly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import {isAbortError} from 'abort-controller-x'
import {Agent, fetch} from 'undici'

export async function getFlyToken(): Promise<string> {
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), 1000)

try {
const res = await fetch('http://localhost/v1/tokens/oidc', {
signal: controller.signal,
signal: AbortSignal.timeout(1000),
dispatcher: new Agent({
connect: {
socketPath: '/.fly/api',
Expand All @@ -16,7 +13,6 @@ export async function getFlyToken(): Promise<string> {
})

const data = await res.text()
clearTimeout(timeout)
return data
} catch (err) {
if (isAbortError(err)) {
Expand Down

0 comments on commit 77717c5

Please sign in to comment.