Futures and Promises (Tutorial)
Bas van den Heuvel
2024-06-07
Overview
- Ilias quiz
- Summary:
- Exercises
Summary
Futures:
- Computation runs without blocking rest of the program
- Completion invokes callback functions
Promises:
- Generalization of futures
- Placeholder for a value that can be set at any time
- Setting invokes callback functions
- Instantiate futures as promises: completion of computation sets
promise’s value
Exercise: Promises without locks: concurrency bugs?
- In the implementation of
promises, we use locks to prevent concurrency bugs
- Your task: assuming we don’t use locks, find and
describe such a concurrency bug scenario
Exercise: Events
- Promises can be further generalized to events
- An event can be fired, invoking any “listening” callback
functions
- Firing an event can happen multiple times
- Your tasks:
- Implement events in Go
- Modify the promise implementation from the lecture as a
specialization of your event implementation