Provide components

Since C++ has no reflection capability, the Worker SDK in C++ makes no attempt to discover your components automatically. Instead, you must explicitly provide the list of components you want to work with to SDK methods that need to know about them (including standard library components). To do this, pass an instance of the worker::Components variadic template class:

// MyComponents can be passed to SDK functions.
const worker::Components<
    // Must include standard library components you care about, too.
    ...> MyComponents;

Since worker::Components is a template, you need to include the generated code for every component you want to work with in order to define MyComponents. However, since this class implements the worker::ComponentRegistry interface, this only needs to be done in one source file:

// Can be called from other translation units without including generated code.
const worker::ComponentRegistry& MyComponents() {
  static const worker::Components<my_schema::FooComponent, my_schema::BarComponent> components;
  return components;

The rest of the "Worker SDK in C++" section assumes that you have defined a MyComponents function like this.

Alternatively, you can use the schema compiler to generate the worker::Components type. For more information, see Schema bundle files.

Updated 8 months ago

Provide components

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.