function updateOutput(groups, groupName, output) {
  output.set('...' + '\n'.repeat((output.get().match(/\n/g) || []).length), false) // Show that it's in progress without changing size

  clearTimeout(output.timeout) // Debounce: If update is called rapidly, cancel last one.

  output.timeout = setTimeout((async () => {
    const promise = handleLater(() => playgroundEval(groups, groupName)) // Wrap with handleLater so that immediate rejection isn't a problem
    output.current = promise // Store the promise to the playground's response globally (tied to this output)

    const [text, error] = await promise // Time passes...

    if (output.current === promise) { // Is the global current promise (for this output block) still the one created by this call?
      if (!error) {
        output.set(text, false)
      } else {
        if (!(error instanceof OPAErrors) || !error.matchesExpected(output.tags)) {
          report(error) // Some extra logging for unexpected errors.
        }
        output.set(error.message, true)
      }
    } else { // A new request was made while waiting for this response, discard it.
      return
    }
  }), 500) // Wait 0.5s before fetching in case they're still typing, will be canceled above if they do.
}
// Update the contents of an output block from a group.
Update the contents of an output block from a group.
Update the contents of an output block from a group .
function updateOutput(groups, groupName, output) {
  output.set('...' + '\n'.repeat((output.get().match(/\n/g) || []).length), false) 
  clearTimeout(output.timeout) 
  output.timeout = setTimeout((async () => {
    const promise = handleLater(() => playgroundEval(groups, groupName)) 
    output.current = promise 
    const [text, error] = await promise 
    if (output.current === promise) { 
      if (!error) {
        output.set(text, false)
      } else {
        if (!(error instanceof OPAErrors) || !error.matchesExpected(output.tags)) {
          report(error) 
        }
        output.set(error.message, true)
      }
    } else { 
      return
    }
  }), 500) 
}
function updateOutput ( groups , groupName , output ) { output . set ( '...' + '\n' . repeat ( ( output . get ( ) . match ( / \n / g ) || [ ] ) . length ) , false ) clearTimeout ( output . timeout ) output . timeout = setTimeout ( ( async ( ) => { const promise = handleLater ( ( ) => playgroundEval ( groups , groupName ) ) output . current = promise const [ text , error ] = await promise if ( output . current === promise ) { if ( ! error ) { output . set ( text , false ) } else { if ( ! ( error instanceof OPAErrors ) || ! error . matchesExpected ( output . tags ) ) { report ( error ) } output . set ( error . message , true ) } } else { return } } ) , 500 ) }
Update the contents of an output block from a group.
Update the contents of an output block from a group .
// Show that it's in progress without changing size // Debounce: If update is called rapidly, cancel last one. // Wrap with handleLater so that immediate rejection isn't a problem // Store the promise to the playground's response globally (tied to this output) // Time passes... // Is the global current promise (for this output block) still the one created by this call? // Some extra logging for unexpected errors. // A new request was made while waiting for this response, discard it. // Wait 0.5s before fetching in case they're still typing, will be canceled above if they do.