{"id":24956833,"url":"https://github.com/andrewstuart/async-traverse","last_synced_at":"2025-03-28T20:38:03.726Z","repository":{"id":58230839,"uuid":"43446031","full_name":"andrewstuart/async-traverse","owner":"andrewstuart","description":"An asynchronous tree traversal utility","archived":false,"fork":false,"pushed_at":"2015-10-05T23:03:33.000Z","size":160,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-03T07:04:19.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/andrewstuart.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}},"created_at":"2015-09-30T16:57:25.000Z","updated_at":"2015-09-30T16:58:02.000Z","dependencies_parsed_at":"2022-08-31T03:30:09.655Z","dependency_job_id":null,"html_url":"https://github.com/andrewstuart/async-traverse","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewstuart%2Fasync-traverse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewstuart%2Fasync-traverse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewstuart%2Fasync-traverse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewstuart%2Fasync-traverse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewstuart","download_url":"https://codeload.github.com/andrewstuart/async-traverse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246100418,"owners_count":20723466,"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":"2025-02-03T06:41:19.641Z","updated_at":"2025-03-28T20:38:03.698Z","avatar_url":"https://github.com/andrewstuart.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async-traverse\n\nA utility library for asynchronous traversal and delegated recursion.\n\n- [Example](#example)\n\n## API\n\nThe async-traverse package exports a factory function for custom traversal\nimplementations.\n\n```javascript\nvar traverser = require('async-traverse');\n```\n\nProvide a callback function with signature `node, next`, and a traversal\nfunction will be returned.\n\n```javascript\nvar traverser = require('async-traverse');\n\nvar t = traverser(function(node, next) {\n  console.log(node);\n  next();\n});\n\n//t is your custom traverser.\n```\n\nPass an array to the provided function, and it will begin to execute your\ncallback, passing it at each iteration the current node, and a `next` function.\nEach time your code calls the next() function (and passes no parameters), your\ncallback will be called again with the next object.\n\nIf your code passes an array, `next(someArray)`, then the traverser will iterate\nover each `someArray` item before returning to its previous items. This allows\nyou to make the decision asynchronously as to whether recursion needs to happen,\nand control which items will be processed asynchronously.\n\n- Recurse on any property\n- Wait for user input before continuing\n- Check with an asynchronous service before recursing\n\nThe initial call to your returned function, `t(someData)`, will return a\npromise for the completed traversal of the tree. The promise is resolved when\nthere are no more items to process.\n\n```javascript\nvar traverser = require('async-traverse');\n\nvar t = traverser(function(node, next) {\n  console.log(node);\n  next();\n});\n\n//t is your custom traverser.\n\n\n```\n\n## Example\n```javascript\nvar traverser = require('async-traverse')\n\nvar tree = [{\n    id: 1,\n    children: [{\n        id: 2,\n        children: [{\n            id: 3\n        }]\n    }]\n},{\n    id: 4,\n    children: [{\n        id: 5,\n        children: [{\n            id: 6\n        }]\n    }]\n}];\n\nvar current, continue;\n\nvar t = traverser(function(node, next) {\n    current = node;\n    continue = next;\n});\n\nt(tree).then(function() {\n  console.log('Done!');\n});\n\nconsole.log(current); // {id: 1, children: [...]}\n\n//Call next to go to the next node.\nnext();\n\nconsole.log(current); // {id: 4, children: [...]}\n\n//Call next with an array of children to iterate over those children before\n//continuing to the next node (or finishing if no nodes left);\n\nnext(current.children);\n\nconsole.log(current); // {id: 5, children: [{id: 6}]}\n\nnext(current.children);\n\nconsole.log(current); // {id: 6}\n\nnext(); //No nodes left at any level; promise will be resolved\n\n// 'Done!' (logged by above promise);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewstuart%2Fasync-traverse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewstuart%2Fasync-traverse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewstuart%2Fasync-traverse/lists"}