IntelliJ warns me of an inappropriate blocking met...
# arrow
k
IntelliJ warns me of an inappropriate blocking method call on
ImageIO.read
here. I understand it probably wants me to put this in a suspend fn and it’s just a linting thing. But since it’s in an
IO.fx
and has
!bind
wrapped around it, I should ignore this linting warning, right? That’s part of the point of IO and !effect, right?
Copy code
fun imageReader(file: File): IO<Either<Throwable, ByteArray>> = IO.fx {
    with(!effect { ImageIO.read(file) }) {
        val argbArray = getRGB(0,0, width, height,null,0, width)
        val buffer = java.nio.ByteBuffer.allocate(4*argbArray.size)
        argbArray.forEach { buffer.putInt(it) }
        buffer.flip()
        buffer.array().slice(0 until argbArray.size*4).toByteArray()
    }
}.attempt()
s
I also got a similar warning for
inputStream.close() inside IO {}
r
Those are blocking calls because they can perform network and File I/O ops but if they are performed in a dispatcher that does not block main or the UI thread they should be fine. If you run that on main as is it would also block right? For blocking ops that take up a thread you may want to use an unbounded or specialized dispatcher for I/O style ops.
k
This is just a command line application, so there’s no UI thread or anything to think about. It’s all about scanning a large directory tree, reading in media files, running a custom hash on the file’s contents (like raw RGB data), storing the hash and canonical path in DB, and using that in the future to speed up dupe detection
ideally this would all become parallel computations for multiple media files, but it runs on a 2 core processor so there’s not much efficiency to gain there. CPU and IO-bound calls are tightly connected (reading bytes of a file and hashing them)
DB is local sqlite