From memory IIS signals through events in the web handler that ultimately sits under the execution pipeline. On linux it would be via Signals e.g. SIGTERM
So the underlying mechanism is going to differ between windows hosting and linux hosting
It wouldn't make sense to allow user code to block an app shutdown - the OS can always force this. I am not aware of a way you could override it.
In terms of best practice, you should really code the function to be as short running as reasonably possible (this for efficinecy) but most important the function should be written to be idempotent and without-side-effect. Meaning; the function can be run multiple times for the same input without causing problems with data (duplication, corruption) or any other side effect to other components. This is important because functions need to be able to handle transient faults as well as scale down events etc.