setTimeout($A.getCallback()) can be used to setTimeout before calling subTab() in Salesforce workspaceAPI. Check the following sample Lightning Aura Component code for reference.
Sample Code:
Aura Component:
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
<lightning:workspaceAPI aura:id="workspace" />
<lightning:utilityBarAPI aura:id="utilitybar"/>
<lightning:button label="Open Tab with Subtab" onclick="{! c.openTabWithSubtab }" />
</aura:component>
JavaScript Controller:
({
openTabWithSubtab : function(component, event, helper) {
var workspaceAPI = component.find("workspace");
workspaceAPI.openTab({
recordId: '0015w0000298JM7AAM',
focus: true
}).then(function(response) {
console.log( ' Parent Response is ' + response );
setTimeout($A.getCallback(function() {
workspaceAPI.openSubtab({
parentTabId: response,
recordId: '0035w000034EYn1AAG',
focus: true
}).then(function(response) {
console.log( 'Child Response is ' + response );
});
}), 1000);
})
.catch(function(error) {
console.log( 'Error is ' + error );
});
}
})