I suspect the `while-no-input` makes no difference here.
And the next three lines can be simplified to:
(setq cursor-type
(if (eolp) cursor-type-at-eol (default-value 'cursor-type)))
;; Oddly this doesn't seem to always work with Emacs 27.1. Never
;; noticed any problem with 26.3.
(add-hook 'post-command-hook 'change-cursor-at-end-of-line)
Nowadays you could also use the `pre-redisplay-function` hook which
could have some advantages, but in any case the limit of the above
approach is that it can't correctly account for all the cases where the
buffer is displayed in several windows, with some windows' cursor at
EOL and others not :-(