harn-stdlib 0.8.39

Embedded Harn standard library source catalog
Documentation
/**
 * std/waitpoint — durable waitpoints for fan-in, fan-out, and long waits.
 *
 * Import with: `import "std/waitpoint"`.
 */
type WaitpointId = string

type WaitpointStatus = "open" | "completed" | "cancelled"

type Waitpoint = {
  id: WaitpointId,
  status: WaitpointStatus,
  created_at: string,
  completed_at: string?,
  cancelled_at: string?,
  completed_by: string?,
  cancelled_by: string?,
  value: any?,
  reason: string?,
  metadata: dict?,
}

type WaitpointCreateOptions = {id?: WaitpointId, metadata?: dict}

type WaitpointCreateInput = WaitpointId | WaitpointCreateOptions | nil

type WaitpointHandle = WaitpointId | dict

type WaitpointWaitOptions = {timeout?: duration}?

type WaitpointTerminalOptions = {by?: string, reason?: string, metadata?: dict}?

type WaitpointTimeoutError = {
  name: "WaitpointTimeoutError",
  category: "timeout",
  message: string,
  wait_id: string,
}

type WaitpointCancelledError = {
  name: "WaitpointCancelledError",
  category: "cancelled",
  message: string,
  wait_id: string,
  waitpoint_ids: list<WaitpointId>,
  reason: string?,
}

/**
 * create.
 *
 * @effects: []
 * @allocation: heap
 * @errors: []
 * @api_stability: stable
 * @example: create(id_or_options)
 */
pub fn create(id_or_options: WaitpointCreateInput = nil) -> Waitpoint {
  if id_or_options == nil {
    return __waitpoint_create()
  }
  return __waitpoint_create(id_or_options)
}

/**
 * wait.
 *
 * @effects: []
 * @allocation: heap
 * @errors: []
 * @api_stability: stable
 * @example: wait(waitpoints, options)
 */
pub fn wait(waitpoints: string | dict | list, options: WaitpointWaitOptions = nil) -> Waitpoint | list<Waitpoint> {
  if type_of(waitpoints) == "list" {
    if options == nil {
      return __waitpoint_wait(waitpoints)
    }
    return __waitpoint_wait(waitpoints, options)
  }
  if options == nil {
    return __waitpoint_wait(waitpoints)
  }
  return __waitpoint_wait(waitpoints, options)
}

/**
 * complete.
 *
 * @effects: []
 * @allocation: heap
 * @errors: []
 * @api_stability: stable
 * @example: complete(waitpoint, value, options)
 */
pub fn complete(waitpoint: WaitpointHandle, value, options: WaitpointTerminalOptions = nil) -> Waitpoint {
  if options == nil {
    return __waitpoint_complete(waitpoint, value)
  }
  return __waitpoint_complete(waitpoint, value, options)
}

/**
 * cancel.
 *
 * @effects: []
 * @allocation: heap
 * @errors: []
 * @api_stability: stable
 * @example: cancel(waitpoint, options)
 */
pub fn cancel(waitpoint: WaitpointHandle, options: WaitpointTerminalOptions = nil) -> Waitpoint {
  if options == nil {
    return __waitpoint_cancel(waitpoint)
  }
  return __waitpoint_cancel(waitpoint, options)
}