{"id":15965117,"url":"https://github.com/planetarydev/synchron","last_synced_at":"2025-09-11T23:33:35.106Z","repository":{"id":65513462,"uuid":"102321107","full_name":"planetarydev/synchron","owner":"planetarydev","description":null,"archived":false,"fork":false,"pushed_at":"2017-09-04T09:28:06.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-18T14:46:14.549Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/planetarydev.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}},"created_at":"2017-09-04T05:13:38.000Z","updated_at":"2017-09-04T06:07:34.000Z","dependencies_parsed_at":"2023-01-26T20:45:14.638Z","dependency_job_id":null,"html_url":"https://github.com/planetarydev/synchron","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/planetarydev%2Fsynchron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planetarydev%2Fsynchron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planetarydev%2Fsynchron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planetarydev%2Fsynchron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/planetarydev","download_url":"https://codeload.github.com/planetarydev/synchron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247183818,"owners_count":20897662,"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-07T17:23:21.804Z","updated_at":"2025-04-04T13:26:05.245Z","avatar_url":"https://github.com/planetarydev.png","language":"JavaScript","readme":"# Synchron\n\nWrapping an async function into a synchron function call **without blocking**.\n\n## Install\n\n```shell\nnpm install synchron --save\n```\n\n## Using Synchron\n\nCreate a new instance of Synchro and use the methods `return` and `throw`. The `wait` method will wait until\n`return` or `throw` was called.\n\n```javascript\nconst { Synchron } = require('synchron');\n\nvar asyncTimeout = new Synchron();\n\nsetTimeout(function(){\n\t// do something\n\tconsole.log('inside setTimeout');\n\t// and than call done\n\tasyncTimeout.done();\n}, 500);\n\n// non-blocking wait until done was called\nasyncTimeout.wait();\nconsole.log('back in main');\n\n// output:\n// -------\n// inside setTimeout\n// back in main\n```\n\nCreate a new instance and pass a function to wrap the asnyc call into a synchron function.\nThe warpped function will run in the context of `Synchron`, so you can use `this.return` and/or `this.throw`.\nIf you like to exit the async function without returning a result just call `this.return()` without a parameter or call `this.done()`.\n\n```javascript\nconst { Synchron } = require('synchron');\n\nvar readFileSync = new Synchron(function(filename) {\n\tvar fs = require('fs');\n\n\tfs.readFile(filename, 'utf8', (err, data) =\u003e {\n\t\tif (err) {\n\t\t\tthis.throw(err);\n\t\t} else {\n\t\t\tthis.return(data);\n\t\t}\n\t});\n});\n\ntry {\n\t// here is the synchron function call\n\tvar data = readFileSync('./testfile.txt');\n\tconsole.log(data);\n} catch (err){\n\t// if an error occours the function will throw it and you can catch it\n\tconsole.log(err); // maybe an error like: \"ENOENT: no such file or directory, open './testfile.txt'\"\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplanetarydev%2Fsynchron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplanetarydev%2Fsynchron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplanetarydev%2Fsynchron/lists"}