function Promise.prototype.cancel(u)if u._status~=Promise.Status.Started then return end u._status=Promise.Status.Cancelled if u._cancellationHook then u._cancellationHook()end coroutine.close(u._thread)if u._parent then u._parent:_consumerCancelled(u)end for u in pairs(u._consumers)do u:cancel()end u:_finalize()end

function Promise.prototype:cancel()
	if self._status ~= Promise.Status.Started then
		return
	end

	self._status = Promise.Status.Cancelled

	if self._cancellationHook then
		self._cancellationHook()
	end

	coroutine.close(self._thread)

	if self._parent then
		self._parent:_consumerCancelled(self)
	end

	for child in pairs(self._consumers) do
		child:cancel()
	end

	self:_finalize()
end
