2023-11-15 15:31:51 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
2025-04-20 16:49:34 +12:00
|
|
|
* Copyright (c) 2025, Shannon Booth <shannon@serenityos.org>
|
2023-11-15 15:31:51 -05:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2025-04-20 16:49:34 +12:00
|
|
|
#include <LibGC/Function.h>
|
|
|
|
#include <LibGC/Root.h>
|
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
|
2023-11-15 15:31:51 -05:00
|
|
|
namespace JS {
|
|
|
|
|
2025-04-20 16:49:34 +12:00
|
|
|
// https://tc39.es/ecma262/#sec-agents
|
2025-06-28 21:39:13 -07:00
|
|
|
class JS_API Agent {
|
2025-04-20 16:49:34 +12:00
|
|
|
public:
|
2025-04-24 16:16:08 +12:00
|
|
|
enum class CanBlock {
|
|
|
|
Yes,
|
|
|
|
No,
|
|
|
|
};
|
|
|
|
|
2025-04-20 16:49:34 +12:00
|
|
|
virtual ~Agent();
|
|
|
|
|
2025-04-24 16:16:08 +12:00
|
|
|
CanBlock can_block() const { return m_can_block; }
|
2025-04-20 16:49:34 +12:00
|
|
|
|
|
|
|
virtual void spin_event_loop_until(GC::Root<GC::Function<bool()>> goal_condition) = 0;
|
2025-04-24 16:16:08 +12:00
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit Agent(CanBlock can_block)
|
|
|
|
: m_can_block(can_block)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// [[CanBlock]]
|
|
|
|
CanBlock m_can_block { false };
|
2025-04-20 16:49:34 +12:00
|
|
|
};
|
|
|
|
|
2025-06-28 21:39:13 -07:00
|
|
|
JS_API bool agent_can_suspend(VM const&);
|
2023-11-15 15:31:51 -05:00
|
|
|
|
|
|
|
}
|