From 05b043fc670609655723f84ab9fac1207b6dce97 Mon Sep 17 00:00:00 2001 From: Mycroft Date: Sat, 16 Jul 2022 15:38:23 +0100 Subject: [PATCH] refactor: async - better readme + performance --- [esx]/async/.editorconfig | 9 -------- [esx]/async/README.md | 43 +++++++------------------------------- [esx]/async/async.lua | 10 +++------ [esx]/async/fxmanifest.lua | 3 ++- 4 files changed, 13 insertions(+), 52 deletions(-) delete mode 100644 [esx]/async/.editorconfig diff --git a/[esx]/async/.editorconfig b/[esx]/async/.editorconfig deleted file mode 100644 index 9b425256..00000000 --- a/[esx]/async/.editorconfig +++ /dev/null @@ -1,9 +0,0 @@ -root = true - -[*] -indent_size = 4 -indent_style = tab -end_of_line = crlf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true \ No newline at end of file diff --git a/[esx]/async/README.md b/[esx]/async/README.md index 12efddbd..9c76d28d 100644 --- a/[esx]/async/README.md +++ b/[esx]/async/README.md @@ -1,42 +1,15 @@ -<<<<<<< HEAD -# esx-legacy -Consolidated esx-legacy files into one repo for easy download since we will not support it -======= -# async -Async utilities for FXServer +

[ESX] Async

Discord - Website - Documentation -## Installation -Set it as a dependency in you fxmanifest.lua -``` -server_script '@async/async.lua' -``` +A very Simple resource that allows resources to run tasks asynchronously. -## Usage -``` -local tasks = {} +## Legal -for i = 1, 100, 1 do - local task = function(cb) - SetTimeout(1000, function() - local result = math.random(1, 50000) +async - asynchronous tasks. - cb(result) - end) - end +Copyright (C) 2015-2022 Jérémie N'gadi - table.insert(tasks, task) -end +This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version. -Async.parallel(tasks, function(results) - print(json.encode(results)) -end) +This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details. -Async.parallelLimit(tasks, 2, function(results) - print(json.encode(results)) -end) - -Async.series(tasks, function(results) - print(json.encode(results)) -end) -``` ->>>>>>> async/master +You should have received a copy Of the GNU General Public License along with this program. If Not, see . diff --git a/[esx]/async/async.lua b/[esx]/async/async.lua index ba55f552..72cf0130 100644 --- a/[esx]/async/async.lua +++ b/[esx]/async/async.lua @@ -1,7 +1,3 @@ -if Citizen and Citizen.CreateThread then - CreateThread = Citizen.CreateThread -end - Async = {} function Async.parallel(tasks, cb) @@ -16,7 +12,7 @@ function Async.parallel(tasks, cb) for i = 1, #tasks, 1 do CreateThread(function() tasks[i](function(result) - table.insert(results, result) + results[#results+ 1] = result remaining = remaining - 1; @@ -39,7 +35,7 @@ function Async.parallelLimit(tasks, limit, cb) local queue, results = {}, {} for i=1, #tasks, 1 do - table.insert(queue, tasks[i]) + queue[queue + 1] = tasks[i] end local function processQueue() @@ -53,7 +49,7 @@ function Async.parallelLimit(tasks, limit, cb) running = running + 1 task(function(result) - table.insert(results, result) + results[#results+ 1] = result remaining = remaining - 1; running = running - 1 diff --git a/[esx]/async/fxmanifest.lua b/[esx]/async/fxmanifest.lua index 84035837..536d794e 100644 --- a/[esx]/async/fxmanifest.lua +++ b/[esx]/async/fxmanifest.lua @@ -1,6 +1,7 @@ fx_version 'cerulean' game 'gta5' -description 'Async' +author 'ESX-Framework' +description 'asynchronous Tasks' shared_script 'async.lua'