{"id":16960198,"url":"https://github.com/dflemstr/tokamak","last_synced_at":"2025-03-21T15:29:33.898Z","repository":{"id":66855368,"uuid":"141157406","full_name":"dflemstr/tokamak","owner":"dflemstr","description":null,"archived":false,"fork":false,"pushed_at":"2018-07-18T11:29:11.000Z","size":77,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-26T10:45:51.972Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dflemstr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-16T15:25:43.000Z","updated_at":"2018-07-18T11:29:12.000Z","dependencies_parsed_at":"2023-03-20T12:24:54.563Z","dependency_job_id":null,"html_url":"https://github.com/dflemstr/tokamak","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflemstr%2Ftokamak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflemstr%2Ftokamak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflemstr%2Ftokamak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflemstr%2Ftokamak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dflemstr","download_url":"https://codeload.github.com/dflemstr/tokamak/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244822280,"owners_count":20516066,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T22:47:31.438Z","updated_at":"2025-03-21T15:29:33.873Z","avatar_url":"https://github.com/dflemstr.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `tokamak` - An experimental async runtime library\n\nThe Tokamak library offers asynchronous execution of synchronous-looking code (similar to\n`async/await` syntax in other programming languages). It does so by intelligently retrying the\ncode when asynchronous operations complete. The core idea is that async operations are expensive\nand synchronous code is cheap.\n\nThe main entry point is `Tokamak.run()`:\n\n```java\nTokamak.run(() -\u003e {\n  // synchronous code here\n});\n```\n\nWithin the Tokamak context, you can write synchronous-looking code as usual, and use\n`Tokamak.await()` when you want to execute asynchronous code. For example:\n\n```java\nfinal int userId = 42;\n// User.fetchName returns a CompletionStage\u003cString\u003e\nfinal String userName = await(User.fetchName(userId));\n// User.fetchAge returns a CompletionStage\u003cInteger\u003e\nfinal int userAge = await(User.fetchAge(userId));\n\nSystem.out.printf(\"User %s has age %d%n\", userName, userAge);\n```\n\nSince the code is retried until all async operations succeed, you need to mark all side-effects\nthat should only be performed once using `Tokamak.once()`:\n\n```java\nfinal int userId = 42;\nfinal String userName = await(User.fetchName(userId));\nonce(this::incrementFetchNameMetric);\nfinal int userAge = await(User.fetchAge(userId));\nonce(this::incrementFetchAgeMetric);\n\nSystem.out.printf(\"User %s has age %d%n\", userName, userAge);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflemstr%2Ftokamak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdflemstr%2Ftokamak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflemstr%2Ftokamak/lists"}