libretto.examples.supermarket

Type members

Classlikes

Our supermarket specializes in the most wanted items in a pandemic, namely toilet paper and beer.

Our supermarket specializes in the most wanted items in a pandemic, namely toilet paper and beer.

object Customers
Companion
class
class Customers[SupermarketImpl <: SupermarketInterface](val supermarket: SupermarketImpl)
Companion
object
object Goods extends GoodsProducer with GoodsConsumer
object Supermarket extends StarterApp

In a pandemic, supermarkets are required to limit the number of customers in the store. A way to achieve it is to provide a limited number of shopping baskets and require that each customer entering the store has a shopping basket. When there are no more baskets, an incoming customer has to wait for a previous customer to leave (and return their basket).

In a pandemic, supermarkets are required to limit the number of customers in the store. A way to achieve it is to provide a limited number of shopping baskets and require that each customer entering the store has a shopping basket. When there are no more baskets, an incoming customer has to wait for a previous customer to leave (and return their basket).

This example demonstrates:

  • concurrency
    • customers come and shop concurrently
  • sequencing
    • a customer can shop only after obtaining a basket
    • a customer can use an item only after paying for it
    • ...
  • mutual exclusion
    • limited number of concurrently shopping customers
      • without side-effects on shared synchronization objects (such as semaphores)
  • linear & session types
    • obligation to return a basket enforced before execution
    • the type Shopping is a protocol between the store and the customer
object baskets
object money