delphi-async
Skill87 starsChanged 5 months agoMITView on GitHub
Especialista em programação assíncrona Delphi. Auto-ativa quando detectar: TTask, TParallel, IFuture, TThread, Synchronize, Queue, TMonitor, TEvent, TCriticalSection, "thread", "assíncrono", "background", "worker", "parallel".
In this repository15 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- delphi-acbrSkill
- delphi-buildSkill
- delphi-claudeignoreSkill
- delphi-e2eSkill
- delphi-encodingSkill
- delphi-firedacSkill
- delphi-fmxSkill
- delphi-laudoSkill
- delphi-legacySkill
- delphi-specSkill
- delphi-spring4dSkill
- delphi-standardsSkill
- delphi-testsSkill
- delphi-writeSkill
The file
Files
Delphi Async
Idioma de saída
Detecte o idioma da primeira mensagem. Padrão: pt-BR. Respeite overrides explícitos.
Referência completa
Consulte knowledge/core/delphi-async.md para padrões detalhados.
Padrão TTask (preferido sobre TThread)
procedure TRelatorioService.GerarRelatorioAsync(
AOnConcluido: TProc<TRelatorio>);
begin
TTask.Run(
procedure
var
LRelatorio: TRelatorio;
begin
LRelatorio := GerarRelatorio; // trabalho pesado na thread background
TThread.Synchronize(nil, // retorna para a thread principal
procedure
begin
AOnConcluido(LRelatorio);
end);
end);
end;Synchronize vs Queue
Synchronize | Queue | |
| Bloqueia? | Sim — aguarda a UI executar | Não — dispara e esquece |
| Quando usar | Preciso do resultado na UI antes de continuar | Notificação, atualização de progresso |
Cancelamento com TTask
var LTask: ITask;
LTask := TTask.Run(
procedure
begin
while not (LTask.Status = TTaskStatus.Canceled) do
begin
// trabalho...
TTask.CurrentTask.CheckCanceled; // lança EOperationCancelled se cancelado
end;
end);
// Para cancelar:
LTask.Cancel;Regras
- Nunca acessar VCL/FMX fora da thread principal — sempre via
SynchronizeouQueue - TCriticalSection para proteção de recursos compartilhados — sempre
try/finally - TMonitor para sincronização mais granular (Delphi XE2+)
- IFuture
<T>quando precisa do resultado da task
Armadilha: captura de variáveis locais
// ERRADO — LId é capturado por referência, pode ter mudado quando a task roda
for LId in LIds do
TTask.Run(procedure begin ProcessarId(LId); end);
// CORRETO — captura por valor via variável local
for LId in LIds do
begin
LIdLocal := LId; // cópia local
TTask.Run(procedure begin ProcessarId(LIdLocal); end);
end;Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

