This gets a bit complicated, but it is possible. You may resume H1-b visa status after you return from the U.S., but must leave with lawful H1-b status. This means that you need to leave the moment that you complete work. You will also have to seek your H1-b stamp once you return to your home country. However, you may decide that it is best to process your I-140 in your home country, rather than an H1-b visa stamp.
The CBP may be skeptical over whether you have an H1-b position to return to. However, if you return as an employment based immigrant, then this may be different. More information on whether your priority date is current is needed.
If your employer is serious about re-hiring you, then a six month departure from the U.S., where you have an H1-b visa stamp that will not expire sooner may allow for some discretion at a port of entry.
This can strategy may lead to CBP skepticism at a port of entry without proof that you have a job to return to. However, it is 'theoretically acceptable.' If you do not have an H1-b visa stamp, then you need to prepare to get a stamp upon return to your home country.
I strongly recommend that you schedule an appointment with an experienced immigration attorney. You must decide whether it is in your best interest to take such risks. Also, whether you can afford the legal fees to properly document and carefully handle any potential CBP concern or skepticism. Again, you may look at other options, such as processing your I-140 abroad, but this depends on other unknown facts.
This is general information and does not create an attorney-client relationship.Ask a similar question