"Wait" function in script without freezing the game?

I was unhappy with the Fade BGM event, so I tried to write my own function in Game_Interpreter for it.

Spoiler: CODE
Ruby:
def audifade(name, duration, pitched = false, pitch = 100)
    counting = 100
    for c in 1..100 do
        volnew = counting * $game_options.master_volume  # <- using vlue's basic options
        volnew *= $game_options.bgm_volume                 # <- using vlue's basic options
        Audio.bgm_play('Audio/BGM/' + name, volnew, pitch, 1)
        p c
        counting -= 1
        wait( duration / 100 )
    end
    Audio.bgm_stop
end


It works perfectly fine, but the only issue is that so far, I'm only aware of using the "wait" command to make the fade effect work, and this has the effect of also freezing the entire game as it does its thing. I wanted to ask if there's anything similar to it I could use that lets the function continue without freezing the game.
For the game to continue, you'll have to allow the main game loop to be processed.
And even then you can only wait for objects (interpreters or similar) in the loop

if the script is part of an object in the loop, then the "wait" functions by telling the main game loop "please skip processing this object for x loops/frames"

That is the reason why a wait in a parallel process reduces lag and only looks like a pause if done in an action button event.

Original thread: https://forums.rpgmakerweb.com/threads/wait-function-in-script-without-freezing-the-game.177761/