im not an expert map maker, but im sure one way to do it is with a statues. The switch opens the door and summons a monster from the statue, and the player has to make it through before the monster hits a pressure plate on the other side which closes the door
the only problem with this is that its unreliable sometimes because monsters ai cant be controlled directly