effect-patterns-concurrency-getting-started
БесплатноБез исполняемых скриптовНе проверенEffect-TS patterns for Concurrency Getting Started. Use when working with concurrency getting started in Effect-TS applications.
от PaulJPhilp★ 807 звёзд на GitHubОб этом скилле
Effect-TS Patterns: Concurrency Getting Started
This skill provides 3 curated Effect-TS patterns for concurrency getting started. Use this skill when working on tasks related to:
- concurrency getting started
- Best practices in Effect-TS applications
- Real-world patterns and solutions
🟢 Beginner Patterns
Race Effects and Handle Timeouts
Rule: Use Effect.race for fastest-wins, Effect.timeout for time limits.
Good Example:
import { Effect, Option } from "effect"
// ============================================
// BASIC RACE: First one wins
// ============================================
const server1 = Effect.gen(function* () {
yield* Effect.sleep("100 millis")
return "Response from server 1"
})
const server2 = Effect.gen(function* () {
yield* Effect.sleep("50 millis")
return "Response from server 2"
})
const raceServers = Effect.race(server1, server2)
Effect.runPromise(raceServers).then((result) => {
console.log(result) // "Response from server 2" (faster)
})
// ============================================
// BASIC TIMEOUT: Limit execution time
// ============================================
const slowOperation = Effect.gen(function* () {
yield* Effect.sleep("5 seconds")
return "Finally done"
})
// Returns Option.none if timeout
const withTimeout = slowOperation.pipe(
Effect.timeout("1 second")
)
Effect.runPromise(withTimeout).then((result) => {
if (Option.isNone(result)) {
console.log("Operation timed out")
} else {
console.log(`Got: ${result.value}`)
}
})
// ============================================
// TIMEOUT WITH FALLBACK
// ============================================
const withFallback = slowOperation.pipe(
Effect.timeoutTo({
duration: "1 second",
onTimeout: () => Effect.succeed("Using cached value"),
})
)
Effect.runPromise(withFallback).then((result) => {
console.log(result) // "Using cached value"
})
// ============================================
// TIMEOUT FAIL: Throw error on timeout
// ============================================
class TimeoutError {
readonly _tag = "TimeoutError"
}
const failOnTimeout = slowOperation.pipe(
Effect.timeoutFail({
duration: "1 second",
onTimeout: () => new TimeoutError(),
})
)
// ============================================
// RACE ALL: Multiple competing effects
// ============================================
const fetchFromCache = Effect.gen(function* () {
yield* Effect.sleep("10 millis")
return { source: "cache", data: "cached data" }
})
const fetchFromDB = Effect.gen(function* () {
yield* Effect.sleep("100 millis")
return { source: "db", data: "fresh data" }
})
const fetchFromAPI = Effect.gen(function* () {
yield* Effect.sleep("200 millis")
return { source: "api", data: "api data" }
})
const raceAll = Effect.raceAll([fetchFromCache, fetchFromDB, fetchFromAPI])
Effect.runPromise(raceAll).then((result) => {
console.log(`Winner: ${result.source}`) // "cache"
})
// ============================================
// PRACTICAL: API with timeout and fallback
// ============================================
const fetchWithResilience = (url: string) =>
Effect.gen(function* () {
const response = yield* Effect.tryPromise(() =>
fetch(url).then((r) => r.json())
).pipe(
Effect.timeout("3 seconds"),
Effect.flatMap((opt) =>
Option.isSome(opt)
? Effect.succeed(opt.value)
: Effect.succeed({ error: "timeout", cached: true })
)
)
return response
})
Rationale:
Use Effect.race when you want the first result from competing effects. Use Effect.timeout to limit how long an effect can run.
Racing and timeouts prevent your app from hanging:
- Redundant requests - Race multiple servers, use fastest response
- Timeouts - Fail fast if operation takes too long
- Fallbacks - Try fast path, fall back to slow path
Understanding Fibers
Rule: Fibers are lightweight threads managed by Effect, enabling efficient concurrency without OS thread overhead.
Good Example:
import { Effect, Fiber } from "effect"
// ============================================
// WHAT IS A FIBER?
// ============================================
// A fiber is a running effect. When you run an effect,
// it executes on a fiber.
const myEffect = Effect.gen(function* () {
yield* Effect.log("Hello from a fiber!")
yield* Effect.sleep("100 millis")
return 42
})
// This runs myEffect on the "main" fiber
Effect.runPromise(myEffect)
// ============================================
// FORKING: Create a new fiber
// ============================================
const withFork = Effect.gen(function* () {
yield* Effect.log("Main fiber starting")
// Fork creates a new fiber that runs independently
const fiber = yield* Effect.fork(
Effect.gen(function* () {
yield* Effect.log("Child fiber running")
yield* Effect.sleep("200
Установить effect-patterns-concurrency-getting-started в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл effect-patterns-concurrency-getting-started?
Effect-TS patterns for Concurrency Getting Started. Use when working with concurrency getting started in Effect-TS applications.
Как установить скилл effect-patterns-concurrency-getting-started?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл effect-patterns-concurrency-getting-started запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic