thread-delay

Guidance for writing Haskell code that waits for other threads or external events without relying too heavily on fixed delays. Haskell is a programming language with built-in support for concurrent code.

In plain words
What is it for?
Use it when reviewing or writing polling, waiting, retry, and thread-synchronization code, including choices such as TMVar or retry policies.
Why use it?
Fixed delays can make programs slow, unreliable, and dependent on machine timing.

Skill for Claude CodeCodex

Part of the haskell-tasuke plugin — 19 skills shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/ncaq/konoka/thread-delay
Any agent
npx skills add ncaq/konoka --skill thread-delay
Clone the repo
git clone --depth 1 https://github.com/ncaq/konoka

Made for: Claude Code, Codex.

Or install haskell-tasuke, the plugin that ships this one along with the rest of its 19 skills.

Per session 46 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 796 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00046 $0.00796
Opus 5 $0.00023 $0.00398
Sonnet 5 $0.00009 $0.00159
Haiku 4.5 $0.00005 $0.00080

Measured 2d ago against content hash 2583d96f6891, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

thread-delay scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/haskell-tasuke/skills/thread-delay/SKILL.md · 78 lines

What it actually says

threadDelay

乱用を避ける

threadDelayはスレッドを指定した時間だけ遅延させる関数です。

threadDelayを乱用するのはやめましょう。

時間に依存するコードは安定性や移植性が低いためです。

次の実行でも同じ時間で処理が完了するとは限りません。 他のマシンでは同じ時間で処理が完了しないかもしれません。

また必然的にその時間だけ実行がストップしてしまうので、 待つように命令した分だけ実行が遅くなります。

代替手段

同期変数

TMVarなどの同期変数が使える場合は正確に同期できます。

Haskellの別のスレッドの実行を待つ場合などに使えます。

リトライ

言語外部のデータやイベントに依存する場合は、 retry: Retry combinators for monadic actions that may fail パッケージなどを使って細かくリトライしてください。

短い単位の繰り返しからだんだん待機時間を増やしていくことで、 固定の待機をするよりは実行のストップが短くなることが見込めます。 また最大待機時間の値を固定値より大きくすることが許容できるため、 実行の安定も見込めます。

リトライポリシーとしては、 ネットワークを経由する場合は、 基本的にfullJitterBackoffを使うのが望ましいでしょう。 待機時間を増やしていきますし、 乱数を入れることで複数の端末が衝突することをある程度避けることが出来ます。

MonadIOの文脈を入れたくないとか、 もう少しシンプルでもいいなら、 exponentialBackoffも選択肢になります。

固定でなければ不都合がある場合はconstantDelayを使うべきです。

全体の待機可能な時間はlimitRetriesByCumulativeDelayで制限してください。

永久的な停止の意図

以下のように意図的に永久的にスレッドを停止する場合は問題ありません。

forever $ threadDelay maxBound

そのスレッドが持つリソースを、 GCに回収されないように保持するために、 こういった永久的なsleepが必要な時もあります。

テストコードでの利用

テストコードを書く時に、 ロジックに実行を待つ部分が実装されていない場合などは、 同期変数を組み込むとロジックを複雑にしてしまうことがあるので仕方ない時もあります。

テストコードなら壊れても致命的ではないので許容することもありますが、 やはり他の方法を使えないか検討するべきです。

とりあえずretry系統を使えばだいたいの場合はthreadDelayを使うよりはマシになるでしょう。

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 78 lines · 46 tokens per session scan A 2583d96f6891

Subscribe to this mod's changes

thread-delay is a skill published in the GitHub repository ncaq/konoka (3 stars, last pushed 4d ago), licensed Apache-2.0. It adds 46 tokens to every session and 796 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.