docs
Loading...
Searching...
No Matches
DestroyedGuard

#include <Ultralight/js/Context.h>

Overview

A callback registered with Context::OnDestroyed(), tied to a C++ object's lifetime.

When an armed guard is destroyed before its context goes away, it removes the callback, so the callback never runs:

class LevelCache {
public:
explicit LevelCache(const js::Context& ctx)
: guard_(ctx.OnDestroyed([this] { Clear(); })) {}
void Clear();
};
JavaScript execution environment for a page.
Definition Context.h:263
A callback registered with Context::OnDestroyed(), tied to a C++ object's lifetime.
Definition Context.h:111

To keep the callback for as long as the context lives instead, call Release().

Destroying a guard after its context went away does nothing (the callback already ran).

Note
Destroying or move-assigning over an armed guard removes the callback, so do it on the Renderer's thread. To give up a guard on another thread, call Release().
Note
operator bool only says whether the guard is armed. It never reflects whether the callback ran or the context is still alive.

Public Member Functions

 DestroyedGuard ()=default
 Create an unarmed guard (removes nothing).
 ~DestroyedGuard ()
 Destructor (removes the callback if the guard is armed).
 DestroyedGuard (DestroyedGuard &&other) noexcept
 Move constructor (other becomes unarmed).
DestroyedGuard & operator= (DestroyedGuard &&other) noexcept
 Move assignment (removes the current callback first if armed, and other becomes unarmed).
 DestroyedGuard (const DestroyedGuard &)=delete
DestroyedGuard & operator= (const DestroyedGuard &)=delete
void Release ()
 Disarm the guard without removing the callback (it still runs when the context goes away).
 operator bool () const
 Whether or not the guard is armed (holds a callback to remove).

Friends

class Context

Constructor & Destructor Documentation

◆ DestroyedGuard() [1/3]

DestroyedGuard ( )
default

Create an unarmed guard (removes nothing).

◆ ~DestroyedGuard()

~DestroyedGuard ( )
inline

Destructor (removes the callback if the guard is armed).

◆ DestroyedGuard() [2/3]

DestroyedGuard ( DestroyedGuard && other)
inlinenoexcept

Move constructor (other becomes unarmed).

◆ DestroyedGuard() [3/3]

DestroyedGuard ( const DestroyedGuard & )
delete

Member Function Documentation

◆ operator bool()

operator bool ( ) const
inlineexplicit

Whether or not the guard is armed (holds a callback to remove).

◆ operator=() [1/2]

DestroyedGuard & operator= ( const DestroyedGuard & )
delete

◆ operator=() [2/2]

DestroyedGuard & operator= ( DestroyedGuard && other)
inlinenoexcept

Move assignment (removes the current callback first if armed, and other becomes unarmed).

◆ Release()

void Release ( )
inline

Disarm the guard without removing the callback (it still runs when the context goes away).

Safe to call from any thread.

◆ Context

friend class Context
friend

The documentation for this class was generated from the following file: