/
githubmirror
/
next.js
Обзор
Документация
Войти
/
githubmirror
/
next.js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
canary
examples/with-temporal/temporal/src/workflows.ts
34 строки
962 B
Steven
chore(examples): use default prettier for examples/templates (#60530)
12 янв 2024, 02:01
Не верифицирован
12 янв 2024, 02:01
4466ba4
Код
Авторство
О чём код?
import { proxyActivities } from "@temporalio/workflow"; // Only import the activity types import type * as activities from "./activities.js"; const { chargeUser, checkAndDecrementInventory, incrementInventory } = proxyActivities<typeof activities>({ startToCloseTimeout: "1 minute", }); export async function order( userId: string, itemId: string, quantity: number, ): Promise<string> { const haveEnoughInventory: boolean = await checkAndDecrementInventory( itemId, quantity, ); if (haveEnoughInventory) { const result: activities.ChargeResult = await chargeUser( userId, itemId, quantity, ); if (result.status === "success") { return `Order successful!`; } else { await incrementInventory(itemId, quantity); return `Unable to complete payment. Error: ${result.errorMessage}`; } } else { return `Sorry, we don't have enough items in stock to fulfill your order.`; } }