Inlife Posted November 13, 2014 Share Posted November 13, 2014 (edited) MTA Lua Asynchronous Computing Description: MTA:SA Async library. If 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. Installation & Instructions: https://github.com/Inlife/mta-lua-async Enable debug, if you need to (it will print some useful information in server console) Async:setDebug(true); Iterate on interval from 1 to 50,000,000 while calculating some data on every iteration (if you run standart "for" cycle, mta server will "freeze" for several seconds) Async:iterate(1, 50000000, function(i) local x = (i + 2) * i; -- heavy opreation outputServerLog(x); end); Iterate over big array of data Async:foreach(vehicles, function(vehicle) vehicle:setHealth(1000); end); There also an options for changing speed of your async caclulations: Async:setPriority("low"); -- better fps async:setPriority("normal"); -- medium async:setPriority("high"); -- better perfomance -- or, more advanced async:setPriority(500, 100); -- 500ms is "sleeping" time, -- 100ms is "working" time, for every current async thread Example: local _connection; -- initialized database connection local vehicles = {}; Async:setDebug(true); Async:setPriority("low"); dbQuery(function(qh) local data = dbPoll(qh, 0); Async:foreach(data, function(vehicle) local _vehicle = createVehicle( vehicle.model, vehicle.x, vehicle.y, vehicle.z ); -- other stuff -- ... table.insert(vehicles, _vehicle); end); -- and run dummy cycle at the same time (just for fun ) Async:iterate(0, 500000, function(num) outputServerLog(num); end); end, _connection, "SELECT * FROM vehicles"); Edited June 22, 2016 by Guest 3 Link to comment
The Creator Posted November 13, 2014 Share Posted November 13, 2014 Useful library. Starred. Keep it up! Link to comment
Inlife Posted November 13, 2014 Author Share Posted November 13, 2014 Useful library. Starred. Keep it up! Thanks ! Link to comment
MTA Team botder Posted November 13, 2014 MTA Team Share Posted November 13, 2014 Looks nice, but your dependency is pretty useless for that library and you could have added that on your own with metatables. Link to comment
Inlife Posted November 13, 2014 Author Share Posted November 13, 2014 Looks nice, but your dependency is pretty useless for that library and you could have added that on your own with metatables. I thought about it. Maybe i'll do this in the next release. ) Link to comment
qaisjp Posted November 20, 2014 Share Posted November 20, 2014 Nice one Inlife OOP ftw. Just one thing, it uses coroutines, which doesn't really utilise true threads. Link to comment
qaisjp Posted November 20, 2014 Share Posted November 20, 2014 I talked to bartbes (I know him), he said he's happy he's finally seen someone use his library Link to comment
spoty Posted November 21, 2014 Share Posted November 21, 2014 looks nice and it can also be used to save scores? Link to comment
Inlife Posted November 21, 2014 Author Share Posted November 21, 2014 Nice one Inlife OOP ftw. Just one thing, it uses coroutines, which doesn't really utilise true threads. Thanks ! Yeah, that's why i tried to imitate something similar to threads. I talked to bartbes (I know him), he said he's happy he's finally seen someone use his library It's awesome library, i using it for 2 years now. Tell bartbes that im very grateful Link to comment
Inlife Posted November 21, 2014 Author Share Posted November 21, 2014 good job Thank you ! ) Link to comment
Inlife Posted November 21, 2014 Author Share Posted November 21, 2014 looks nice and it can also be used to save scores? I think so, it mostly depends on your realization. Can you provide some example ? Link to comment
ma2med Posted November 21, 2014 Share Posted November 21, 2014 There is error I can't use it: 'attempt to call global 'class' (a nil value) at line 7' Link to comment
The Creator Posted November 21, 2014 Share Posted November 21, 2014 There is error I can't use it: 'attempt to call global 'class' (a nil value) at line 7' Download latest version of slither.lua (Dependency) Download latest version of async.lua Update your meta.xml <script src="path/to/lib/slither.lua" type="shared" /> -- it. <script src="path/to/lib/async.lua" type="shared" /> Check it. Link to comment
ma2med Posted November 22, 2014 Share Posted November 22, 2014 There is error I can't use it: 'attempt to call global 'class' (a nil value) at line 7' Download latest version of slither.lua (Dependency) Download latest version of async.lua Update your meta.xml <script src="path/to/lib/slither.lua" type="shared" /> -- it. <script src="path/to/lib/async.lua" type="shared" /> Check it. I already do that but I changed the script location (path/to/lib/slither.lua) to (slither.lua) same for the second one Link to comment
Inlife Posted November 22, 2014 Author Share Posted November 22, 2014 There is error I can't use it: 'attempt to call global 'class' (a nil value) at line 7' Download latest version of slither.lua (Dependency) Download latest version of async.lua Update your meta.xml <script src="path/to/lib/slither.lua" type="shared" /> -- it. <script src="path/to/lib/async.lua" type="shared" /> Check it. I already do that but I changed the script location (path/to/lib/slither.lua) to (slither.lua) same for the second one Changing path is ok. I updated installation instructions. https://github.com/Inlife/mta-lua-async#installation Thanks for feedback Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now