No that is not possible. Script callbacks are supposed to return immediately so any kind of "thread management" (sleep, while, etc) is not available.
What you need to do is to set a variable to true in the onNoteOn callback, then query it somehow (either using a timer callback or other callbacks) and reset it to false in the onNoteOff callback.