/**
 * Normalise an asynchronous map-provider route request. Consumers can ignore a
 * response that belongs to an older/closed panel without treating it as a
 * route failure.
 */
export const resolveDirectionsRequest = async ( request, isCurrent = () => true ) => {
	try {
		const route = await request();
		if ( ! isCurrent() ) return { state: 'stale' };
		if ( ! route ) return { state: 'unavailable' };
		return { state: 'success', route: route === true ? {} : route };
	} catch ( error ) {
		if ( ! isCurrent() ) return { state: 'stale' };
		return { state: 'failed', error };
	}
};
