-- by default, warns

local function warnWithTracebackOnError(func, shouldNotWarn)
	return xpcall(func, function(err)
		if not shouldNotWarn then
			warn(tostring(err) .. "\n" .. debug.traceback())
		end
		return false, err
	end)
end

function SafeSpawn.new(func, shouldNotWarn)
	local success, err = warnWithTracebackOnError(coroutine.wrap(func), shouldNotWarn)
	if not success and not shouldNotWarn then
		warn(err)
	end
	return success, err
end

return SafeSpawn
