function Promise.prototype.cancel(k)if k._status~=Promise.Status.Started then return end k._status=Promise.Status.Cancelled if k._cancellationHook then k._cancellationHook()end if k._parent then k._parent:_consumerCancelled(k)end for k in pairs(k._consumers)do k:cancel()end k:_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

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

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

	self:_finalize()
end
