Code after "await anim.animation_finished" never run

Godot Version

4.3

Question

I am creating a simple game in which you have to fight with space ships but today i found one problem. I was scripting an enemy ship when I found that in function code after “await anim.animation_finished” never run
even though animation finishes. Here is ship’s code:

extends CharacterBody2D


@onready var player = $"../Player"
@onready var anim = $AnimatedSprite2D
@onready var shootZone = $ShootZone
@onready var timer = $MoveTimer
@onready var scoutBulletScene = preload("res://scout_bullet.tscn")

const SPEED = 750

var attacking = 0
var readyToAttack = 1
var readyToMove = 1

var collidingObjects = []



func _process(delta: float) -> void:
	check()
	
	if not attacking and readyToMove:
		if position.x < player.position.x:
			position.x += SPEED * delta
			
		elif position.x > player.position.x:
			position.x -= SPEED * delta
			
	if attacking:
		attack()


func _on_checking_area_body_entered(body: Node2D) -> void:
	if body.is_in_group("player"):
		timer.start()
		readyToMove = 0
		collidingObjects.append(body)


func _on_checking_area_body_exited(body: Node2D) -> void:
	if body.is_in_group("player"):
		collidingObjects.erase(body)
		
		
func _on_move_timer_timeout() -> void:
	readyToMove = 1
	

func attack():
	anim.play("attack")
	
	if (anim.frame == 2 or anim.frame == 4 or anim.frame == 6) and readyToAttack:
		readyToAttack = 0
		var scoutBullet = scoutBulletScene.instantiate()
		scoutBullet.position = shootZone.global_position
		get_parent().add_child(scoutBullet)
		print(readyToAttack)
		
	elif not (anim.frame == 2 or anim.frame == 4 or anim.frame == 6):
		readyToAttack = 1
		
		
func check():
	if len(collidingObjects):
		attacking = 1
		
	else:
		await anim.animation_finished
		anim.play("idle")
		attacking = 0

If your animations loop, finish will not be emitted.