<commit_before>discard """
  output: '''
OK
OK
OK
OK
'''
"""

when defined(upcoming):
  import asyncdispatch, times, osproc, streams

  const supportedPlatform = defined(linux) or defined(freebsd) or
                            defined(netbsd) or defined(openbsd) or
                            defined(macosx)

  proc waitEvent(ev: AsyncEvent, closeEvent = false): Future[void] =
    var retFuture = newFuture[void]("waitEvent")
    proc cb(fd: AsyncFD): bool =
      retFuture.complete()
      if closeEvent:
        return true
      else:
        return false
    addEvent(ev, cb)
    return retFuture

  proc waitTimer(timeout: int): Future[void] =
    var retFuture = newFuture[void]("waitTimer")
    proc cb(fd: AsyncFD): bool =
      retFuture.complete()
    addTimer(timeout, true, cb)
    return retFuture

  proc waitProcess(p: Process): Future[void] =
    var retFuture = newFuture[void]("waitProcess")
    proc cb(fd: AsyncFD): bool =
      retFuture.complete()
    addProcess(p.processID(), cb)
    return retFuture

  proc delayedSet(ev: AsyncEvent, timeout: int): Future[void] {.async.} =
    await waitTimer(timeout)
    ev.setEvent()

  proc timerTest() =
    var timeout = 200
    var errorRate = 40.0
    var start = epochTime()
    waitFor(waitTimer(200))
    var finish = epochTime()
    var lowlimit = float(timeout) - float(timeout) * errorRate / 100.0
    var highlimit = float(timeout) + float(timeout) * errorRate / 100.0
    var elapsed = (finish - start) * 1_000 # convert to milliseconds
    if elapsed >= lowlimit and elapsed < highlimit:
      echo "OK"
    else:
      echo "timerTest: Timeout = " & $(elapsed) & ", but must be inside of [" &
                                   $lowlimit & ", " & $highlimit & ")"

  proc eventTest() =
    var event = newAsyncEvent()
    var fut = waitEvent(event)
    asyncCheck(delayedSet(event, 500))
    waitFor(fut or waitTimer(1000))
    if fut.finished:
      echo "OK"
    else:
      echo "eventTest: Timeout expired before event received!"

  proc processTest() =
    when defined(windows):
      var process = startProcess("ping.exe", "",
                                 ["127.0.0.1", "-n", "2", "-w", "100"], nil,
                                 {poStdErrToStdOut, poUsePath, poInteractive,
                                 poDemon})
    else:
      var process = startProcess("/bin/sleep", "", ["1"], nil,
                                 {poStdErrToStdOut, poUsePath})
    var fut = waitProcess(process)
    waitFor(fut or waitTimer(2000))
    if fut.finished and process.peekExitCode() == 0:
      echo "OK"
    else:
      echo "processTest: Timeout expired before process exited!"

  when supportedPlatform:
    import posix

    proc waitSignal(signal: int): Future[void] =<commit_msg>Disable time error test.<commit_after>discard """
  output: '''
OK
OK
OK
OK
'''
"""

when defined(upcoming):
  import asyncdispatch, times, osproc, streams

  const supportedPlatform = defined(linux) or defined(freebsd) or
                            defined(netbsd) or defined(openbsd) or
                            defined(macosx)

  proc waitEvent(ev: AsyncEvent, closeEvent = false): Future[void] =
    var retFuture = newFuture[void]("waitEvent")
    proc cb(fd: AsyncFD): bool =
      retFuture.complete()
      if closeEvent:
        return true
      else:
        return false
    addEvent(ev, cb)
    return retFuture

  proc waitTimer(timeout: int): Future[void] =
    var retFuture = newFuture[void]("waitTimer")
    proc cb(fd: AsyncFD): bool =
      retFuture.complete()
    addTimer(timeout, true, cb)
    return retFuture

  proc waitProcess(p: Process): Future[void] =
    var retFuture = newFuture[void]("waitProcess")
    proc cb(fd: AsyncFD): bool =
      retFuture.complete()
    addProcess(p.processID(), cb)
    return retFuture

  proc delayedSet(ev: AsyncEvent, timeout: int): Future[void] {.async.} =
    await waitTimer(timeout)
    ev.setEvent()

  proc timerTest() =
    waitFor(waitTimer(200))
    echo "OK"

  proc eventTest() =
    var event = newAsyncEvent()
    var fut = waitEvent(event)
    asyncCheck(delayedSet(event, 500))
    waitFor(fut or waitTimer(1000))
    if fut.finished:
      echo "OK"
    else:
      echo "eventTest: Timeout expired before event received!"

  proc processTest() =
    when defined(windows):
      var process = startProcess("ping.exe", "",
                                 ["127.0.0.1", "-n", "2", "-w", "100"], nil,
                                 {poStdErrToStdOut, poUsePath, poInteractive,
                                 poDemon})
    else:
      var process = startProcess("/bin/sleep", "", ["1"], nil,
                                 {poStdErrToStdOut, poUsePath})
    var fut = waitProcess(process)
    waitFor(fut or waitTimer(2000))
    if fut.finished and process.peekExitCode() == 0:
      echo "OK"
    else:
      echo "processTest: Timeout expired before process exited!"

  when supportedPlatform:
    import posix

    proc waitSignal(signal: int): Future[void] =
{'fraction_non_alphanumeric': 0.1178343949044586, 'fraction_numerical': 0.01393312101910828, 'mean_word_length': 2.441780821917808, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7566222', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1478, 'n_words': 405}