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

Switch to Evaera's 'roblox-lua-promise' #240

Open
OttoHatt opened this issue Jan 1, 2022 · 1 comment
Open

Switch to Evaera's 'roblox-lua-promise' #240

OttoHatt opened this issue Jan 1, 2022 · 1 comment

Comments

@OttoHatt
Copy link
Contributor

OttoHatt commented Jan 1, 2022

This could be a complete nightmare, but would be a great help in making these libraries more user friendly. The upcoming v4 release fixes all of the weird quirks, so it should be ready enough to use...

A lot of the fixes are smallish syntax things, i.e.

-- Quenty promises
function HumanoidTracker:PromiseNextHumanoid()
	if self.Humanoid.Value then
		return Promise.resolved(self.Humanoid.Value)
	end

	if self._maid._nextHumanoidPromise then
		return self._maid._nextHumanoidPromise
	end

	local promise = Promise.new()

	local conn = self.Humanoid.Changed:Connect(function(newValue)
		if newValue then
			promise:Resolve(newValue)
		end
	end)

	promise:Finally(function()
		conn:Disconnect()
	end)

	self._maid._nextHumanoidPromise = promise

	return promise
end

-- Evaera promises
function HumanoidTracker:PromiseNextHumanoid()
	if self.Humanoid.Value then
		return Promise.resolve(self.Humanoid.Value)
	end

	if self._maid._nextHumanoidPromise then
		return self._maid._nextHumanoidPromise
	end

	local promise = Promise.fromEvent(self.Humanoid.Changed, function(val)
		return val ~= nil
	end)

	self._maid._nextHumanoidPromise = promise

	return promise
end

Would also need to add a special case for the maid accepting promises, as these don't implement a .destroy method. I've been slowly converting libraries as I use them, would PRs be accepted on some separate branch?

@Quenty
Copy link
Owner

Quenty commented Jan 5, 2022

I'm planning on providing promise-compatibility with eryn's promises, and then maybe eventually switching over to eryn promises full time.

This will probably need to go in phases. First, adding an appropriate API surface that accepts andThen callbacks, and a suite of unit tests. Then, adjusting API calls around the codebase to use Eryn's promises layering, and then finally, maybe transparently switching out certain packages promises.

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

2 participants