Concepts

Asynchronous Work

Introduction

Asynchronous programming is a technique that enables your program to start a potentially long-running task and still be able to be responsive to other events while that task runs, rather than having to wait until that task has finished. Once that task has finished, your program is presented with the result.

Many functions provided by browsers, especially the most interesting ones, can potentially take a long time, and therefore, are asynchronous.

Front-end developers have several low-level techniques available that allow for managing these long-running tasks without starving the main UI thread including:

  1. Callbacks

  2. Promises

  3. async/await

In KOS, unlike traditional web applications, almost every action is asynchronous in that most tasks are long-running and most don’t follow a familiar request/response execution pattern. In many cases, a given operation can be composed of multiple child operations with a full graph of potential operations that are assembled dynamically while the operation is in progress.

  • need to address the cases where the full graph of work to be performed is indeterminate when the action is first executed.

  • also doesn’t cleanly support incremental progress updates, especially when the full scope of the operation is dynamically composed at execution time.

  • KOS provides a robust async capability (Future Work) in which complex operations can be performed while returning a work item to the UI that appears as a trackable operation with concepts of completed progress and time remaining.

  • The UI SDK ensures that any operation initiated from the front end that returns a Future Work will automatically create a Work Model that will register for any updates and report them back to the consuming application.

  • The Work model will ensure that common concepts such as the current work item (step), estimated time remaining and total progress are kept up to date while managing any additional client data that might accompany the work updates.

Work Manager

  • The KOS Core Framework will automatically register to listen for work items that come across the WebSocket transport and route them to the Work Manager.

Registering the Work Model

Setting up an application to make use of the Work infrastructure is as simple as registering some models provided by the kos-core-model package.

// Import the Work Model along with other Core KOS Models
import { coreModels } from "@coca-cola/kos-core-model";

// Register the Core KOS Models with an application
export const Registry: IKosRegistry = {
  models: {
    ...coreModels,
  },
  preloadModels: [],
};

...

Work Model

In your application, when operations return Future Work, it is possible to retrieve the Work Model to start tracking progress.

import { WorkManager } from "@coca-cola/kos-core-model";

const response = await this.doSomethingThatReturnWork();

// Get the work ID from the response and retrieve the work from the WorkManager
const work = WorkManager.getWork(response.data.id);
Previous
Next
On this page
Java Development
Seamlessly transition from Legacy+ systems to Freestyle microdosing and advanced distributed dispense systems.
UI Development
Using KOS SDKs, integrating Consumer and Non-consumer facing UIs becomes seamless, giving you less hassle and more time to create.
Video Library
Meet some of our development team, as they lead you through the tools, features, and tips and tricks of various KOS tools.
Resources
Familiarize yourself with KOS terminology, our reference materials, and explore additional resources that complement your KOS journey.
Copyright © 2024 TCCC. All rights reserved.