Skip to content

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

@OttoHatt

Description

@OttoHatt

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions