fp-async
यह क्या करती है
यह tool आपके code में समय लेने वाले कामों (asynchronous operations) को व्यवस्थित और प्रबंधित करने में मदद करता है, खासकर जब वे विफल भी हो सकते हैं। यह `TaskEither` नाम के तरीके का उपयोग करता है ताकि errors साफ़ और व्यवस्थित ढंग से संभाले जा सकें, और उलझन से बचा जा सके।
कब इस्तेमाल करें
- ✓जब आपको ऐसे काम संभालने हों जिनमें समय लगता है, जैसे API से डेटा लाना या database में जानकारी सेव करना।
- ✓अगर आपको async code में error handling व्यवस्थित करने में दिक्कत हो रही है, जिसमें बहुत सारे nested `try/catch` blocks हैं।
- ✓ऐसे async operations की श्रृंखला बनाने के लिए जो एक के बाद एक चलें और जिनके errors एक जैसे ढंग से संभाले जाएँ।
Skill का लिंक
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/fp-async/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं `TaskEither` का उपयोग करके API से डेटा कैसे लाऊँ और network errors को कैसे संभालूँ?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह tool `TaskEither` का उपयोग करता है, जो एक डिब्बे की तरह है जिसमें या तो सफल परिणाम हो सकता है या कोई error। यह आपको async operations को एक के बाद एक जोड़ने देता है, और अगर कोई एक विफल हो जाए तो error पकड़कर साफ़ तरीके से संभाल लिया जाता है, बिना program के प्रवाह को रोके।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Practical Async Patterns with fp-ts
Stop writing nested try/catch blocks. Stop losing error context. Start building clean async pipelines that handle errors properly.
TaskEither is simply an async operation that tracks success or failure. That's it. No fancy terminology needed.
Detailed Guide
Read the detailed guide before executing this skill. It retains the complete procedure and reference material. Treat its safety, prerequisites, and validation requirements as mandatory. For focused work, load the relevant sections; for end-to-end work, read the guide completely.
When to Use
- You need async error handling in TypeScript with
TaskEither. - The task involves wrapping Promises, composing API calls, or replacing nested
try/catchflows. - You want practical fp-ts async patterns instead of academic explanations.
// TaskEither<Error, User> means:
// "An async operation that either fails with Error or succeeds with User"
5. Real API Examples
Complete Fetch Wrapper
// types.ts
interface ApiError {
code: string
message: string
status: number
details?: unknown
}
// api.ts
const createApiError = (
code: string,
message: string,
status: number,
details?: unknown
): ApiError => ({ code, message, status, details })
const request = <T>(
url: string,
options: RequestInit = {}
): TE.TaskEither<ApiError, T> =>
TE.tryCatch(
async () => {
const response = await fetch(url, {
headers: {
'Content-Type': 'application/json',
...options.headers,
},
...options,
})
if (!response.ok) {
const body = await response.json().catch(() => ({}))
throw createApiError(
body.code || 'HTTP_ERROR',
body.message || response.statusText,
response.status,
body
)
}
// Handle 204 No Content
if (response.status === 204) {
return undefined as T
}
return response.json()
},
(error): ApiError => {
if (typeof error === 'object' && error !== null && 'code' in error) {
return error as ApiError
}
return createApiError(
'NETWORK_ERROR',
error instanceof Error ? error.message : 'Request failed',
0
)
}
)
// API client
const api = {
get: <T>(url: string) => request<T>(url),
post: <T>(url: string, body: unknown) =>
request<T>(url, {
method: 'POST',
body: JSON.stringify(body)
}),
put: <T>(url: string, body: unknown) =>
request<T>(url, {
method: 'PUT',
body: JSON.stringify(body)
}),
delete: (url: string) =>
request<void>(url, { method: 'DELETE' }),
}
// Usage
const getUser = (id: string) => api.get<User>(`/api/users/${id}`)
const createUser = (data: CreateUserDto) => api.post<User>('/api/users', data)
const updateUser = (id: string, data: UpdateUserDto) => api.put<User>(`/api/users/${id}`, data)
const deleteUser = (id: string) => api.delete(`/api/users/${id}`)
Database Operations (Prisma Example)
import { PrismaClient, Prisma } from '@prisma/client'
type DbError =
| { _tag: 'NotFound'; entity: string; id: string }
| { _tag: 'UniqueViolation'; field: string }
| { _tag: 'ConnectionError'; cause: unknown }
const prisma = new PrismaClient()
const wrapPrisma = <T>(
operation: () => Promise<T>
): TE.TaskEither<DbError, T> =>
TE.tryCatch(
operation,
(error): DbError => {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
if (error.code === 'P2002') {
const field = (error.meta?.target as string[])?.join(', ') || 'unknown'
return { _tag: 'UniqueViolation', field }
}
if (error.code === 'P2025') {
return { _tag: 'NotFound', entity: 'Record', id: 'unknown' }
}
}
return { _tag: 'ConnectionError', cause: error }
}
)
// Repository pattern
const userRepository = {
findById: (id: string): TE.TaskEither<DbError, User> =>
pipe(
wrapPrisma(() => prisma.user.findUnique({ where: { id } })),
TE.chain(user =>
user
? TE.right(user)
: TE.left({ _tag: 'NotFound', entity: 'User', id })
)
),
findByEmail: (email: string): TE.TaskEither<DbError, User | null> =>
wrapPrisma(() => prisma.user.findUnique({ where: { email } })),
create: (data: CreateUserInput): TE.TaskEither<DbError, User> =>
…
अक्सर पूछे जाने वाले सवाल
`TaskEither` क्या है?
`TaskEither` एक ऐसा तरीका है जो उस async operation को दर्शाता है जो या तो सफल हो सकता है या विफल। इसे ऐसे पैकेट की तरह समझें जिसमें या तो अपेक्षित परिणाम हो या हुए error का विवरण।
`try/catch` की जगह इसका उपयोग क्यों करें?
`TaskEither` से कई nested `try/catch` blocks से बचा जा सकता है, जो code को उलझा सकते हैं। यह async operations में errors संभालने का अधिक व्यवस्थित और साफ़ तरीका देता है।
क्या इसे इस्तेमाल करने के लिए advanced programming जानना ज़रूरी है?
ज़रूरी नहीं। इसमें कुछ functional programming की अवधारणाएँ इस्तेमाल होती हैं, लेकिन मुख्य विचार यह है कि समय लेने वाले कामों में error handling को सरल बनाया जाए, जिससे code पढ़ने में आसान हो।
जानकारी
लेखक का मूल विवरण
Practical async patterns using TaskEither - clean pipelines instead of try/catch hell, with real API examples
लोकप्रियता
- GitHub स्टार
- 48k
- रैंकिंग में स्थान
- #4638
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
00-andruia-consultant
48kआपके एजेंट को AI प्रोजेक्ट शुरू करने या उन्हें बेहतर बनाने में मदद करता है। यह code का विश्लेषण करता है, tools सुझाता है और स्पेनिश भाषा में action plan बनाता है।
007
48kआपका एजेंट security audit और threat modeling करता है। यह प्रोजेक्ट को हमलों और कमजोरियों से बचाने में काम आता है।
10-andruia-skill-smith
48kआपके एजेंट को AI tools बनाने या उन्हें बेहतर करने में मदद करता है। यह तय करता है कि tools कैसे काम करेंगे, documentation लिखता है और structure की जांच करता है।
20-andruia-niche-intelligence
48kआपका एजेंट किसी खास industry का summary बनाता है। भरोसेमंद स्रोतों की मदद से यह प्रोजेक्ट का संदर्भ, नियम, इस्तेमाल के तरीके और जोखिम समझने में मदद करता है।
मिलती-जुलती skills
api-connector-builder
280kयह आपके एजेंट को मौजूदा pattern के हिसाब से नए API connections बनाने देता है। जब बिना कोई नया तरीका बनाए एक और integration जोड़ना हो, तब इसका इस्तेमाल करें।
api-design
280kयह आपके एजेंट को best practices के हिसाब से REST APIs डिज़ाइन करने में मदद करता है। यह तय करने में काम आता है कि APIs आपस में कैसे बात करें, errors कैसे दिखें, और data को कैसे व्यवस्थित करें।
backend-patterns
280kआपके एजेंट को server-side architecture patterns और database optimization में मदद करता है। server पर चलने वाला code बनाने या review करने के लिए उपयोगी है।