SHARE
TWEET

Untitled

a guest Jun 26th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use "collections"
  2. use "promises"
  3.  
  4. class OneTimeAuth
  5.   new iso create(auth: AmbientAuth) => None
  6.  
  7. actor IDService
  8.   var id_count: USize = 1
  9.  
  10.   be apply(auth: OneTimeAuth iso, promise: Promise[USize]) =>
  11.     promise(id_count = id_count + 1)
  12.  
  13. actor AuthorizedActor
  14.   let service: IDService
  15.   var id: (USize | None) = None
  16.  
  17.   new create(service': IDService) =>
  18.     service = service'
  19.  
  20.   be request_new_id(auth: OneTimeAuth iso) =>
  21.     let promise = Promise[USize]
  22.       .> next[None](
  23.         {(id: USize)(self: AuthorizedActor = this) => self._update_id(id) })
  24.     service(consume auth, promise)
  25.  
  26.   be _update_id(id': USize) =>
  27.     id = id'
  28.     @printf[None]("%s\n".cpointer(), id.string().cpointer())
  29.  
  30. actor Main
  31.   new create(env: Env) =>
  32.     let service = IDService
  33.     for i in Range(0, 10) do
  34.       try
  35.         let foo = AuthorizedActor(service)
  36.         let auth = OneTimeAuth(env.root as AmbientAuth)
  37.         foo.request_new_id(consume auth)
  38.       end
  39.     end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top