Have comm layer wait until all lines are sent before disconnect
Have comm layer wait until all lines are sent before disconnect

Added parameter "wait" to "close" method, defaults to True. Will have the
close method wait for all lines to be sent that are currently in the send queue.

In case of an error, no waiting will be done.

Made it necessary to correctly track task completion in the send queue, also
made that change to the command queue while at it.

Backported from devel, commit 7f2476e51313185e38a1ff1cc9a7055692d41e99

CapnBry/OctoPrint,Javierma/OctoPrint-TFG,nickverschoor/OctoPrint,shohei/Octoprint,bicephale/OctoPrint,ryanneufeld/OctoPrint,foosel/OctoPrint,Jaesin/OctoPrint,nickverschoor/OctoPrint,Jaesin/OctoPrint,senttech/OctoPrint,shohei/Octoprint,CapnBry/OctoPrint,beeverycreative/BEEweb,Salandora/OctoPrint,ryanneufeld/OctoPrint,nickverschoor/OctoPrint,MoonshineSG/OctoPrint,beeverycreative/BEEweb,Jaesin/OctoPrint,bicephale/OctoPrint,beeverycreative/BEEweb,Javierma/OctoPrint-TFG,MoonshineSG/OctoPrint,JackGavin13/octoprint-test-not-finished,foosel/OctoPrint,Javierma/OctoPrint-TFG,beeverycreative/BEEweb,MoonshineSG/OctoPrint,JackGavin13/octoprint-test-not-finished,MoonshineSG/OctoPrint,leductan-nguyen/RaionPi,nickverschoor/OctoPrint,foosel/OctoPrint,ryanneufeld/OctoPrint,Salandora/OctoPrint,JackGavin13/octoprint-test-not-finished,leductan-nguyen/RaionPi,senttech/OctoPrint,shohei/Octoprint,foosel/OctoPrint,Jaesin/OctoPrint,CapnBry/OctoPrint,bicephale/OctoPrint,CapnBry/OctoPrint,ryanneufeld/OctoPrint,JackGavin13/octoprint-test-not-finished,Javierma/OctoPrint-TFG,Salandora/OctoPrint,senttech/OctoPrint,shohei/Octoprint,leductan-nguyen/RaionPi,bicephale/OctoPrint,Salandora/OctoPrint,shohei/Octoprint,senttech/OctoPrint,leductan-nguyen/RaionPi