Hello, does someone know if it's actually possible...
# coroutines
b
Hello, does someone know if it's actually possible to use Spring Couroutine Repositories in MapStruct to lookup an object? This is something i come up with, but it blocks the Request forever.
Copy code
@Mapper(uses = [ObjectIdMapper::class, LocalDateToInstantMapper::class])
abstract class SubstitutionBlockingMapper {

    @Autowired
    lateinit var driverRepository: DriverRepository

    @Autowired
    lateinit var driverMapper: DriverMapper

    @Mappings(
        Mapping(source = "entity.id", target = "id"),
        Mapping(source = "driverId", target = "driver", qualifiedByName = ["driverIdToObject"]),
        Mapping(source = "substitutionDriverId", target = "substitutionDriver", qualifiedByName = ["driverIdToObject"]),
    )
    abstract fun convertToDto(entity: SubstitutionEntity): SubstitutionWithDriver

    @Named("driverIdToObject")
    fun map(driverId: ObjectId): Driver {
        return runBlocking(Dispatchers.Default) {
            driverRepository.findById(driverId)!!.let { driverMapper.convertToDTO(it) }
        }
    }
}
Is there a general pattern i can use to call suspended functions from a coroutine-unaware code?