Skip to content

Commit

Permalink
Move conditional TIMEOUT_DURATION to top of file
Browse files Browse the repository at this point in the history
  • Loading branch information
ning-y committed Aug 7, 2018
1 parent 50e98ae commit 55bcc12
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, runInContext, Result as SourceResult } from 'js-slang'
import { SourceError } from 'js-slang/dist/types'

const TIMEOUT_DURATION = 20000
const TIMEOUT_DURATION = process.env.NODE_ENV !== 'test' ? 20000 : 1000

type AwsEvent = {
graderPrograms: string[]
Expand Down Expand Up @@ -90,10 +90,7 @@ const run = async (chap: number, stdPrg: string, gdrPrg: string): Promise<Output
}

const catchTimeouts = (slangPromise: Promise<Result>): Promise<Result> => {
const timeoutDuration = process.env.NODE_ENV !== 'test'
? TIMEOUT_DURATION
: 1000 // facilitate testing
return Promise.race([slangPromise, timeout(timeoutDuration)])
return Promise.race([slangPromise, timeout(TIMEOUT_DURATION)])
}

const timeout = (msDuration: number): Promise<TimeoutResult> => (
Expand Down

0 comments on commit 55bcc12

Please sign in to comment.