The carburetor doesn't fill up with gas as soon as the petcock is turned on. There is a float bowl in the carburetor, which has a float inside of it. When the gas level in the float bowl reaches a certain level, the float will rise and push on a float valve, which will shut off the flow of gas into the carburetor.
When the gas level in the float bowl drops, the float will fall and the float valve will open, allowing more gas to flow into the carburetor. This process ensures that the gas level in the carburetor is kept at a constant level, which is necessary for the carburetor to function properly.