Services

Every dependency is represented as a service.

What is a service?

A service is a unit within a larger Jetwhisk app. Any functionality that is not completely functional (or pure) should be encapsulated in a service to allow smarter management.

Instances

But services can't just exist. So on every instantiation, a new instance is created and stored alongside any others. By default, instances are not destroyed until the Orchestrator shuts down, but they can be set to destroy sooner if needed.

The nice thing about the instance system is that you never have to think about the instances themselves. Jetwhisk will just plumb together instances, so all you have to think about is the service layer.

Instance status

  • Ready

    This instance is ready to be depended upon.

  • Active

    This instance is currently executing instructions.

  • Satisfied

    Every dependency of this instance is ready.

  • Failed

    This instance was not able to run to completion.

  • Done

    This instance has done all that it needs to do and can be safely destroyed.

Instantiation scopes

  • Global

    A singular, shared instance of the service will be made available to all other requesting instances.

  • Sandbox

    Each requesting service will get access to its own instance of the service, shared between all its instances.

  • Instanced

    Each requesting instance gets its own copy of the service.

Service types

  • Trigger

    For a self-contained service that should be considered ephemeral, like setting up a global variable, adding a polyfill or checking the status of something. These shouldn't have APIs accessible through the service system.

  • Persistent

    For a service that has a lifecycle and that will be used in code.

Statuses between types

Service type
Trigger
Persistent

Ready when...

The called function exits without an error

The service says it is

Active when...

The service is satisfied but not done

Any method is executing

Satisfied when...

When all dependencies are ready

When all dependencies are ready

Failed when...

The called function throws an error

The service either throws an error or fails to instantiate

Done when...

The called function exits without an error

The service says it is

Last updated