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

Promise:await() method #28

Open
Joakker opened this issue Aug 4, 2024 · 0 comments
Open

Promise:await() method #28

Joakker opened this issue Aug 4, 2024 · 0 comments

Comments

@Joakker
Copy link

Joakker commented Aug 4, 2024

Is your feature request related to a problem? Please describe.
Javascript has a promise system similar to the one offered by this crate. However, it also comes with a big problem called Callback Hell, which basically looks like this:

image

The solution JS opted for is to introduce the await keyword. Since this crate is supposed to be language agnostic, it should instead add a method for that functionality.

This is important because, if you want to use more than one value from rust at a time, you would have to nest the callbacks, like so:

get_my_value1():and_then(function(value1)
	get_my_value2():and_then(function(value2)
		-- etc.
	end)
end)

Describe the solution you'd like

With the :await() method, the above code should look like this. Much nicer:

local value1 = get_my_value1()
	:and_then(function(value)
		return value
	end)
	:await()

local value2 = get_my_value2()
	:and_then(function(value)
		return value
	end)
	:await()

--- etc

The await method should wait until the callback function returns, and then give back the final value.

Additional context
Nested callbacks look ugly

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