Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with LuaTuples in async functions #2449

Open
Lolikarbuzik opened this issue Aug 31, 2023 · 0 comments
Open

Problem with LuaTuples in async functions #2449

Lolikarbuzik opened this issue Aug 31, 2023 · 0 comments

Comments

@Lolikarbuzik
Copy link

Lolikarbuzik commented Aug 31, 2023

TS.async and TS.await functions return only one argument meaning that a Tuple promise only has first argument returned instead of every

example
Code only will run in a async function

async function Test() {
	return $tuple(1, 2);
}
// returns only 1 instead of 1, 2
print(await Test());

fixed portion of the RuntimeLib starts at line 136
I havent tested rejection

function TS.async(callback)
	return function(...)
		local n = select("#", ...)
		local args = { ... }
		return Promise.new(function(resolve, reject)
			coroutine.wrap(function()
				local resArray = {pcall(callback, unpack(args, 1, n))}
				local ok = resArray[1]
				if ok then
					resolve(unpack(resArray, 2))
				else
					reject(unpack(resArray, 2))
				end
			end)()
		end)
	end
end

function TS.await(promise)
	if not Promise.is(promise) then
		return promise
	end
	
	local array = {promise:awaitStatus()}
	local status = array[1]
	if status == Promise.Status.Resolved then
		return unpack(array, 2)
	elseif status == Promise.Status.Rejected then
		error(array[2], 2)
	else
		error("The awaited Promise was cancelled", 2)
	end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant