For the purpose of this example I'm going to assume your world is built up of blocks, like terraria. Im sure you could adapt this if it isn't, but anyways.
What I would do is something along the lines of, When a "block" of water is created, spawn "check" blocks to the down, left, and right of it. If these check blocks collide with a solid block, say "stone", then delete the check block, and do nothing else. This way, your "check" block spawns to the right of the water source, checks if theres a solid wall to the right of it, if there is, then no water flows to that block. If there isn't, however, a block at this spot, delete the check block and replace it with a water block.
It wouldn't be this simple, you'd have to have it check if theres a solid underneath it, otherwise it would flow off for infinity at the same height, stuff like that, but hopefully you get the general idea of what I mean. I'm sure theres a much easier way of doing this with arrays, but I personally like to avoid arrays.