{"id":15663063,"url":"https://github.com/nikku/nashorn-async","last_synced_at":"2025-07-08T15:04:15.906Z","repository":{"id":24000441,"uuid":"27384174","full_name":"nikku/nashorn-async","owner":"nikku","description":"Simple async support for Nashorn (the Java 8 JavaScript Engine)","archived":false,"fork":false,"pushed_at":"2023-08-15T15:44:02.000Z","size":14,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-08T15:03:58.726Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikku.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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},"funding":{"github":["nikku"]}},"created_at":"2014-12-01T14:56:24.000Z","updated_at":"2024-03-19T05:37:39.000Z","dependencies_parsed_at":"2024-10-23T08:25:47.749Z","dependency_job_id":"4e83fe79-0e64-4cc8-a98b-fedee15e9b82","html_url":"https://github.com/nikku/nashorn-async","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nikku/nashorn-async","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikku%2Fnashorn-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikku%2Fnashorn-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikku%2Fnashorn-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikku%2Fnashorn-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikku","download_url":"https://codeload.github.com/nikku/nashorn-async/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikku%2Fnashorn-async/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264292907,"owners_count":23586059,"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-03T13:35:23.021Z","updated_at":"2025-07-08T15:04:15.870Z","avatar_url":"https://github.com/nikku.png","language":"JavaScript","funding_links":["https://github.com/sponsors/nikku"],"categories":[],"sub_categories":[],"readme":"# nashorn-async\n\n[![CI](https://github.com/nikku/nashorn-async/actions/workflows/CI.yml/badge.svg)](https://github.com/nikku/nashorn-async/actions/workflows/CI.yml)\n\nAsynchronous scripting support for [Nashorn](http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html).\n\nThis project adds optional asynchronous scripting support to javascript snippets evaluated with nashorn.\n\nA snippet may call `var done = async()` to switch to asynchronous mode.\nIn asynchronous mode the overall script execution will not finish until\nall timers and intervals got cleared or elapsed _and_ the `done` callback\ngot invoked with `(err, result)`.\n\n\n## Example Code\n\nA simple asynchronous script:\n\n```javascript\nvar done = async();\n\nvar timer = setTimeout(function() {\n\n  // do work\n  done(null, 'WORK DONE!');\n}, 100);\n```\n\nA timeout may also be cleared:\n\n```javascript\nclearTimeout(timer);\ndone();\n```\n\nScripts may be synchronous, too and simply return a computed value:\n\n```javascript\nfunction doWork() {\n  return 'WORK DONE!';\n}\n\nreturn doWork();\n```\n\n## Async Helpers\n\nInside a script the following async helpers are available:\n\n* `setTimeout`\n* `clearTimeout`\n* `setInterval`\n* `clearInterval`\n\n\n## Using the library from Java\n\nExecuting scripts with async support from Java:\n\n```java\n\nScriptRunner execution = new ScriptRunner(script);\n\ntry {\n  Object result = execution.execute();\n} catch (Exception e) {\n  // catches both synchronous and\n  // asynchronous exceptions\n}\n```\n\n\n## Extending the implementation\n\nSimply evaluate the [`event-loop.js`](https://github.com/nikku/nashorn-async/blob/master/src/main/resources/js/event-loop.js) script that adds optional async support in your script prior to evaluating the target script inside a `exec(function() { ...actual script... })` block. See [ScriptRunner](https://github.com/nikku/nashorn-async/blob/master/src/main/java/de/nixis/scripting/ScriptRunner.java) for details.\n\n\n## Compatible Libraries\n\nUsing this library the following projects have been reported to work with Nashorn:\n\n* [pdfmake](http://pdfmake.org)\n\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikku%2Fnashorn-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikku%2Fnashorn-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikku%2Fnashorn-async/lists"}