NevermoreEngine icon indicating copy to clipboard operation
NevermoreEngine copied to clipboard

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

Open OttoHatt opened this issue 3 years ago • 1 comments

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?

OttoHatt avatar Jan 01 '22 13:01 OttoHatt

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.

Quenty avatar Jan 05 '22 01:01 Quenty