如何每 60 秒刷新一次会话并将其显示在 Pharo 的成绩单上?

How can I refresh a session for every 60 second and display it on transcript with Pharo?

|a b |
a := ZnClient new.
a get: 'http://cloud-storage.com/login'.
a
formAt: 'username' put: 'jom';
formAt: 'password' put: 'mypass';
post;
get: 'http://cloud-storage.com/my-file'.
"Here I want to refresh the session for every 60sec and"
"to checking for newer data"
b := a maxNumberOfRedirects:60
Transcript show: b; cr.

我想实现一种方法,可以每 60 秒刷新一次 ZnClient 会话,以检查我登录的服务器上是否有更新的数据。我尝试了 pharo 的重定向方法,但它似乎不起作用。或者说它没有显示任何内容。有什么想法吗?

| session data |

session := ZnClient new url: 'http://cloud-storage.com'.

"Login"
session path: '/login';
    formAt: 'email' put: 'jom';
    formAt: 'password' put: 'mypass';
    post.

"Get data"
data := session path: '/my-file'; get; contents.

"Check for new data every 60 secs for maximum 100 tries"
[
    100 timesRepeat: [
        | newData |
        (Delay forSeconds: 60) wait.
        newData := session path: '/my-file'; get; contents.
        (data ~= newData) ifTrue: [Transcript show: newData; cr]
    ]
] fork.

注意。尽管有上面的示例代码,您可能还是想考虑在 ZnClient 中尝试 If-Modified-Since 方法。