-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathpa_cars.mo
42 lines (37 loc) · 1.4 KB
/
pa_cars.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Stateless Suspendable Workflow
// ==============================
// Creating an Account for the PA parking service
// - Client: Insert Car data and holder's name
// - Server: Validate car is registered under the given name
// - Client: Pick a parking spot from a Google Map like interface + time
// - Server: Register the parking spot for the user
type Car = { model : Text; plate : Text };
type DMV = actor { check : Car -> async CarInfo };
type CarInfo = {
model : Text;
plate : Text;
isValid : Bool;
wasStolen : Bool;
expires : Nat;
};
actor class PACars(dmv : DMV) {
public func verifyCarInformation(user : User, car : Car) : async ?(shared (Location, TimeSpan) -> async Result) {
let carInfo = await dmv.check(car);
if (carInfo.isValid and not carInfo.wasStolen) {
return ?(shared func (location : Location, time : TimeSpan) : async Result {
return reserveSpot(user, carInfo, location, time);
})
} else {
return null;
}
};
private func reserveSpot(user : User, carInfo : CarInfo, location : Location, timeSpan : TimeSpan) : Result {
// Do the actual work of registering the parking spot for the
// given car in the given time span
return null;
};
public type Location = { lat : Float; long : Float };
public type TimeSpan = { start : Int; end : Int };
public type Result = ?({ reservationId : Text });
public type User = { name : Text };
};