What you can do is make sure you don't do any work in addon 2 until addon 1 has loaded. You can check for the addon loading stage using ADDON_LOADED event.
The way I do it is to monitor for when the active addon is loaded and any required addon is loaded during the ADDON_LOADED event. During that same event check stage I check to make sure all the addons that are needed to be loaded are loaded before progressing further.
Edit:
For example. This is a section from one of my nUI Plugins. To access the nUI stuff it needs to wait until nUI has loaded before doing its own work.
Lua Code:
--[[ Create the InfoPanel Plugin ]]--
local plugin = CreateFrame( "Frame", addon:GetInfoPanelName(), nUI_Dashboard.Anchor );
plugin.active = true;
--[[ Handle the addons Events ]]--
local function onEvent(self,event,arg1,arg2,arg3)
if ( event == "ADDON_LOADED" ) then
if arg1 == "nUI" then
addon.nUILoaded = true
elseif arg1 == addonName then
if not addon.nUILoaded then
LoadAddOn("nUI")
end
addon.nUILoaded = IsAddOnLoaded("nUI")
addon.addonLoaded = true
addon.plugin = plugin
addon:OnAddonLoaded()
self:UnregisterEvent(event)
end
end
end
What this basically does is checks if nUI is loaded and set a flag. And check if the plugin addon is loaded. If nUI is loaded first, its just the case of waiting for the plugin to load. But if the plugin is loaded first you can force the base addon to load and check that it has loaded before proceeding. Hopefully it will help you see what you could do with your addon situation to work for you.