package org.wcs.app;

import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import org.wcs.helper.SseHelper;

@Component
@RequiredArgsConstructor
public class ApplicationClose implements ApplicationListener<ContextClosedEvent> {

    private final SseHelper sseHelper;

    /**
     * 监听应用关闭事件
     *
     * @param event 应用关闭事件
     */
    @Override
    public void onApplicationEvent(@NonNull ContextClosedEvent event) {
        // 关闭所有 SSEEmitter
        sseHelper.closeAllEmitter();
    }
}
