完蛋了,为什么我感觉 PHP 的语法这么优雅呢
temporal 官网示例
python:
@workflow.defn
class SleepForDaysWorkflow:
# Send an email every 30 days, for the year
@workflow.run
async def run(self) -> None:
for i in range(12):
# Activities have built-in support for timeouts and retries!
await workflow.execute_activity(
send_email,
start_to_close_timeout=timedelta(seconds=10),
)
# Sleep for 30 days (yes, really)!
await workflow.sleep(timedelta(days=30))
ruby:
# Send an email every 30 days, for the year
class SleepForDaysWorkflow < Temporalio::Workflow::Definition
def execute
12.times do
# Activities have built-in support for timeouts and retries!
Temporalio::Workflow.execute_activity(
SendEmailActivity,
start_to_close_timeout: 10
)
# Sleep for 30 days (yes, really)!
Temporalio::Workflow.sleep(30 * 24 * 60 * 60)
end
end
end
C#:
[Workflow]
public class SleepForDaysWorkflow
{
// Send an email every 30 days, for the year
[WorkflowRun]
public async Task RunAsync()
{
for (int i = 0; i < 12; i++)
{
// Activities have built-in support for timeouts and retries!
await Workflow.ExecuteActivityAsync(
(Activities act) => act.SendEmail(),
new() { StartToCloseTimeout = TimeSpan.FromSeconds(10) });
// Sleep for 30 days (yes, really)!
await Workflow.DelayAsync(TimeSpan.FromDays(30));
}
}
}
PHP:
class SleepForDaysWorkflow implements SleepForDaysWorkflowInterface
{
// Send an email every 30 days.
public function sleepForDays(): void
{
for ($i = 0; $i < 12; $i++) {
// Activities have timeouts, and will be retried by default!
$this->sendEmailActivity->sendEmail();
// Sleep for 30 days (yes, really)!
Workflow::sleep(30 * 24 * 60 * 60)
}
}
}
感觉对于 java 程序员 php 的心智负担好小啊