Guest User

Untitled

a guest
May 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. Class('DataStore.Async', {
  2.  
  3. trait : JooseX.CPS,
  4.  
  5.  
  6. continued : {
  7.  
  8. methods : {
  9.  
  10. log : function () {
  11. var resultFromLog = // somehow get the response from logging operation
  12.  
  13. this.CONTINUE(resultFromLog)
  14.  
  15. return whatever
  16. },
  17.  
  18.  
  19. save : function (data) {
  20. this.log().then(function (resultFromLog) {
  21.  
  22. var CONT = this.CONT
  23.  
  24. require('fs').saveFile('filename.txt', data, function (err, written) {
  25. if (err) {
  26. CONT.THROW(err)
  27.  
  28. return
  29. }
  30.  
  31. CONT.CONTINUE(written)
  32. })
  33. }).now()
  34. }
  35. }
  36. }
  37. })
  38.  
  39.  
  40. var store = new DataStore.Async
  41.  
  42.  
  43. store.save('some data').then(function (written) {
  44.  
  45. // do smth
  46.  
  47. }).CATCH(function (exception) {
  48.  
  49. // do smth
  50.  
  51. }).FINALLY(function () {
  52.  
  53. // do smth
  54.  
  55. }).now()
Add Comment
Please, Sign In to add comment