Creating a /give queue

Im working on a datapack where you can achieve custom advancements that give the player a reward. these rewards are items stored inside vaults so you have to open them using a trial key. now technically i had the reward system set up that just runs a function that gives the player his earned vault. the problem with that: if you have a full inventory your vault will just disappear and you lose your reward. what i want to do now is I want to create a queue where all of your rewards are appended to and once you have space in your inventory you will get your rewards one by one (depending on how much space you have in your inv). i already have a function that checks if you have space in your inventory. all i need is that item queue. I know that i will need to use macros for that (and probably a player id system?), though I have never used macros before and have 0 clue on how to code all of that.
Continue to help post