Put the sugar and egg yolks in a bowl. Beat well with a wire whisk until the mixture reaches the ribbon stage, when the yolks will thicken slightly and become pale yellow. Beat in the cornstarch.
Add the milk gradually, beating constantly. Pour the mixture into a saucepan and cook, stirring constantly with a wooden spatula, until the sauce thickens enough to coat the spoon. Do not overcook and do not let the mixture boil at any point or it will curdle. Remove the saucepan from the heat and continue to beat for about thirty seconds.
Strain the sauce through a fine sieve and season with vanilla. If desired, rum or cognac may be substituted for the vanilla. Serve hot or cold over cakes, puddings, cooked fruits or ice cream.