{"id":17298030,"url":"https://github.com/inlife/mta-lua-async","last_synced_at":"2026-03-17T11:34:07.977Z","repository":{"id":23188872,"uuid":"26545175","full_name":"inlife/mta-lua-async","owner":"inlife","description":"⏱ Non-blocking iteration and computing","archived":false,"fork":false,"pushed_at":"2017-09-06T10:00:52.000Z","size":12,"stargazers_count":34,"open_issues_count":0,"forks_count":11,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-14T11:41:23.020Z","etag":null,"topics":["async","lua","mta","mta-server","mtasa"],"latest_commit_sha":null,"homepage":"","language":"Lua","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/inlife.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":"2014-11-12T16:33:52.000Z","updated_at":"2024-08-04T11:36:30.000Z","dependencies_parsed_at":"2022-08-21T21:30:31.681Z","dependency_job_id":null,"html_url":"https://github.com/inlife/mta-lua-async","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/inlife/mta-lua-async","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fmta-lua-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fmta-lua-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fmta-lua-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fmta-lua-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inlife","download_url":"https://codeload.github.com/inlife/mta-lua-async/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fmta-lua-async/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30622756,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T11:26:08.186Z","status":"ssl_error","status_checked_at":"2026-03-17T11:24:37.311Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["async","lua","mta","mta-server","mtasa"],"created_at":"2024-10-15T11:17:53.116Z","updated_at":"2026-03-17T11:34:07.959Z","avatar_url":"https://github.com/inlife.png","language":"Lua","readme":"# mta-lua-async\n\n## Description:\n\nMTA:SA Async library.\nIf you have some heavy cyclic operations, that are dropping \"Infinite/too long execution\", or operations that \"freeze\" your server for couple seconds, you can use this library. It supports multiple running threads at a time.\n\n## Installation:\n\n* Download latest version of **[async.lua](https://github.com/Inlife/mta-lua-async/blob/master/async.lua)**\n* Put it inside your resource folder\n* Update resource **meta.xml** file:\n\n```xml\n...\n\u003cscript src=\"path/to/lib/async.lua\" type=\"shared\" /\u003e\n...\n```\n\n**That's all, You are ready to go! :)**\n\n## Usage\n\nEnable debug, if you need to (it will print some useful information in server console)\n\n```lua\nAsync:setDebug(true);\n```\n\nIterate on interval from 1 to 50,000,000 while calculating some data on every iteration\n\u003e(if you run standart \"for\" cycle, mta server will \"freeze\" for several seconds)\n\n```lua\nAsync:iterate(1, 50000000, function(i)\n    local x = (i + 2) * i; -- heavy opreation\n    outputServerLog(x);\nend);\n```\n\nIterate over big array of data\n\n```lua\nAsync:foreach(vehicles, function(vehicle)\n    vehicle:setHealth(1000);\nend);\n```\n\nThere also an options for changing speed of your async caclulations:\n\n```lua\nAsync:setPriority(\"low\");    -- better fps\nAsync:setPriority(\"normal\"); -- medium\nAsync:setPriority(\"high\");   -- better perfomance\n\n-- or, more advanced\nAsync:setPriority(500, 100);\n-- 500ms is \"sleeping\" time, \n-- 100ms is \"working\" time, for every current async thread\n```\n## Example\nLoad all vehicles from database, and create them in the game world (without lags)\n\n```lua\nlocal _connection; -- initialized database connection\nlocal vehicles = {};\n\nAsync:setDebug(true);\nAsync:setPriority(\"low\");\n\ndbQuery(function(qh)\n    local data = dbPoll(qh, 0); \n    \n    Async:foreach(data, function(vehicle)\n        \n        local _vehicle = createVehicle( vehicle.model, vehicle.x, vehicle.y, vehicle.z );\n        -- other stuff\n        -- ...\n        table.insert(vehicles, _vehicle);\n        \n    end);\n    \n    -- and run dummy cycle at the same time (just for fun :p)\n    Async:iterate(0, 500000, function(num)\n        outputServerLog(num);\n    end);\n    \nend, _connection, \"SELECT * FROM vehicles\");\n```\n\n## Upgrading\n\nIf you've used library before \"Singleton\" update:\n\n```lua\n-- warning! old example\nlocal async = Async();\nasync:iterate(function(i)\n\toutputDebugString(i);\nend);\n```\n\nYou can easily simulate it, just by adding \"_\" before Async class name:\n\n```lua\n-- warning! updated old example (localized scope, not recommended)\nlocal async = _Async();\nasync:iterate(function(i)\n\toutputDebugString(i);\nend);\n```\n\nBut, still: it's not recommended! :P\n\n## Under the hood:\nIf you want to create independent/scope-isolated instance of Async manager, you can do it that way:\n\n```lua\nlocal isolatedAsync = _Async();\n```\n\nYou can find kinda well documented code inside async.lua file. If you need some help, you can always create an issue.\n\n## Other \nLibrary uses [bartbes/slither](https://bitbucket.com/bartbes/slither) class library. Check it out. @Bartbes, thank you so much! :)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlife%2Fmta-lua-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finlife%2Fmta-lua-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlife%2Fmta-lua-async/lists"}