Skip to main content

Overview

atRiskAll() is an async generator that yields all at-risk users above a threshold, handling pagination automatically. Use it when you need to process the full list without managing offset / total yourself.

Signature

churn.atRiskAll(options?: AtRiskAllOptions): AsyncGenerator<AtRiskUser>

AtRiskAllOptions

threshold
number
Minimum score to include (0–1). Default: 0.5.
plan
string
Filter by plan.
pageSize
number
Number of users to fetch per internal page. Default: 100.

Examples

Process all at-risk users

for await (const user of churn.atRiskAll({ threshold: 0.7 })) {
  await sendOutreachEmail(user.userId, user.recommendation)
}

Collect into an array

const users: AtRiskUser[] = []
for await (const user of churn.atRiskAll()) {
  users.push(user)
}
console.log(`Total at-risk: ${users.length}`)

Early exit

// Process only the first 50, then stop
let count = 0
for await (const user of churn.atRiskAll({ threshold: 0.8 })) {
  await alert(user)
  if (++count >= 50) break
}

With transformations

// Build a map of userId → risk for a bulk email tool
const riskMap = new Map<string, AtRiskUser>()

for await (const user of churn.atRiskAll({ threshold: 0.6, plan: 'pro' })) {
  riskMap.set(user.userId, user)
}

vs atRisk()

atRisk()atRiskAll()
ReturnsOne pageAll pages (streaming)
PaginationManualAutomatic
MemoryBoundedUnbounded (collects all if you push to array)
Use caseDashboard, previewBulk processing, exports