Example
machine BankServer { var database: Database; start state Init { entry (initialBalance: map[int, int]){ database = new Database((server = this, initialBalance = initialBalance)); goto WaitForWithdrawRequests; } } state WaitForWithdrawRequests { on eWithDrawReq do (wReq: tWithDrawReq) { var currentBalance: int; var response: tWithDrawResp; // read the current account balance from the database currentBalance = ReadBankBalance(database, wReq.accountId); // if there is enough money in account after withdrawal if(currentBalance - wReq.amount >= 10) { UpdateBankBalance(database, wReq.accountId, currentBalance - wReq.amount); response = (status = WITHDRAW_SUCCESS, accountId = wReq.accountId, balance = currentBalance - wReq.amount, rId = wReq.rId); } else // not enough money after withdraw { response = (status = WITHDRAW_ERROR, accountId = wReq.accountId, balance = currentBalance, rId = wReq.rId); } // send response to the client send wReq.source, eWithDrawResp, response; } } } == See also ==