{"id":17434610,"url":"https://github.com/aneldev/dyna-try","last_synced_at":"2025-10-12T22:21:40.542Z","repository":{"id":57217582,"uuid":"448062575","full_name":"aneldev/dyna-try","owner":"aneldev","description":null,"archived":false,"fork":false,"pushed_at":"2022-01-25T09:59:15.000Z","size":182,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-01T17:38:17.856Z","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/aneldev.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":"2022-01-14T18:04:54.000Z","updated_at":"2022-01-14T18:05:17.000Z","dependencies_parsed_at":"2022-08-28T21:01:07.811Z","dependency_job_id":null,"html_url":"https://github.com/aneldev/dyna-try","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/aneldev/dyna-try","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdyna-try","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdyna-try/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdyna-try/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdyna-try/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aneldev","download_url":"https://codeload.github.com/aneldev/dyna-try/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdyna-try/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279013247,"owners_count":26085250,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-17T09:07:43.671Z","updated_at":"2025-10-12T22:21:40.502Z","avatar_url":"https://github.com/aneldev.png","language":"JavaScript","readme":"# dynaTry with timeout\n\n**Example**\n\nSuppose we have this api get method:\n```\nconst getPerson = (id: string): Promise\u003cIPerson | null\u003e =\u003e {\n  ...\n}\n```\n\nLet's try to load this within 5000 seconds\n\n```\ndynaTry\u003cIPerson | null\u003e({\n  timeout: 5000,\n  try: () =\u003e getPerson('ID400232'),\n})\n  .then(person =\u003e {\n    // Do somthing with this person\n  })\n  .catch(error =\u003e {\n    // Call for getPerson's errors\n    // or due to timeout.\n  });\n```\n\nLet's have specific error for the timeout.\n\n```\ndynaTry\u003cIPerson | null\u003e({\n  timeout: 5000,\n  try: () =\u003e getPerson('ID400232'),\n  timeoutError: new Error('Client timeout'),\n})\n  .then(person =\u003e {\n    // Do somthing with this person\n  })\n  .catch(error =\u003e {\n    // Called for getPerson's errors\n    // In case of timeout the \"Client timeout\" will be here\n  });\n```\n\n# API\n\n```\ndynaTry = \u003cTResolve\u003e(\n  args: {\n    try: () =\u003e Promise\u003cTResolve\u003e;       // The timedout promise\n    timeout: number;                    // Timeout in ms\n    timeoutError?: IDynaError | Error;  // Custom timeout error\n  },\n): Promise\u003cTResolve\u003e                    // dynaTry can resolves value\n```\n\nBy default, this error is returned in timeout error.\n\n```\ndynaError({\n  code: 600408,\n  message: `Try timed out (${timeout}ms)`,\n})\n```\n\nWhere is the same as...\n```\nnew Error(`Try timed out (${timeout}ms)`);\n```\nbut without the `code`.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faneldev%2Fdyna-try","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faneldev%2Fdyna-try","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faneldev%2Fdyna-try/lists"}