<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Yes, this programming style sounds really interesting but totally different. :)</p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div>
<div class="_rp_T4" id="Item.MessagePartBody">Funny, the only real sender of #future in my image comes from Squot :-)
<div class="_rp_U4 ms-font-weight-regular ms-font-color-neutralDark rpHighlightAllClass rpHighlightBodyClass" id="Item.MessageUniqueBody" style="font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont">
<div dir="ltr">
<div id="divtagdefaultwrapper"><font face="Calibri,Helvetica,sans-serif,EmojiFont,Apple Color Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI Symbol,Android Emoji,EmojiSymbols">
<div id="Signature">
<div style="margin:0px"><font style="font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont">
<div><font size="3" color="black"><span style="font-size:12pt"><a href="http://www.hpi.de/" target="_blank" rel="noopener noreferrer" id="LPNoLP"><font size="2"><span id="LPlnk909538"><font color="#757B80"></font></span></font></a></span></font></div>
</font></div>
</div>
</font></div>
</div>
</div>
</div>
<div class="_rp_T4" id="Item.MessagePartBody"><br>
</div>
<div class="_rp_T4" id="Item.MessagePartBody">> <span style="font-size: 12pt;">Similar alternative without promises:</span>
<div>> - Instead of a promise, store a MessageSend in the model.</div>
<div><span style="font-size: 12pt;">> - In the client of the model, store all necessary state to continue in instance variables.</span></div>
<div>> - Do not expect a return value from opening the view for the model.</div>
<div>> - Have the model send the message to self upon continuation.</div>
<div><br>
</div>
<div>And I would append observer pattern to this list, which is just a special case of your last point.</div>
<div><br>
</div>
<div>These proposals actually appear a bit easier and more convenient. I would like to use the same solution for DialogWindows as well which suffer from the same problem. But #inform: should be called as usual and hide any concurrent logic from the caller.
 How would you identify the object to resume after the information, if you called, for example, nil inform: #foo? I think the only way, without creating an extra DialogWindowModel, would be #spawnNewProcessDuring: ...</div>
<div><br>
</div>
<div>Best,</div>
<div>Christoph</div>
</div>
</div>
<div><font size="2" color="#808080"></font></div>
</div>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Von:</b> Squeak-dev <squeak-dev-bounces@lists.squeakfoundation.org> im Auftrag von Jakob Reschke <forums.jakob@resfarm.de><br>
<b>Gesendet:</b> Mittwoch, 15. Januar 2020 21:39:33<br>
<b>An:</b> The general-purpose Squeak developers list<br>
<b>Betreff:</b> Re: [squeak-dev] The Inbox: Monticello-ct.712.mcz</font>
<div> </div>
</div>
<div>
<div dir="ltr">Since you mentioned the #future, I recently tried to wrap modal dialog (well not really, it is not exclusive, it just has a synchronous API to obtain the result) with a promise interface and came up with the following. If I thought it through
 correctly, it should not lose the continuation even when the UI process is terminated and replaced (via Ctrl+., abandon, for example). Haven't tested it yet, though. Would anyone like to review?
<div><br>
</div>
<div>In the model...</div>
<div>selectedChangesWithTitle: titleString<br>
| builder |<br>
builder := ToolBuilder default.<br>
view := builder open: self label: titleString.<br>
promise ifNil: [promise := Promise new].<br>
self future resumeModalRequest. "will resolve the promise"<br>
^ promise<br>
</div>
<div><br>
</div>
<div>resumeModalRequest<br>
view ifNil: [self error: 'Tool was not opened yet'].<br>
promise ifNil: [self error: 'Tool was not opened with selectedChangesWithTitle:'].<br>
[ToolBuilder default runModal: view]<br>
ifCurtailed:<br>
["Make sure we will notice in a new UI process when the view is closed."<br>
self future resumeModalRequest].<br>
"If we finally get here, the view was closed."<br>
self accepted ifTrue: [promise resolve] ifFalse: [promise reject].<br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">Am Mi., 15. Jan. 2020 um 21:32 Uhr schrieb Jakob Reschke <<a href="mailto:forums.jakob@resfarm.de">forums.jakob@resfarm.de</a>>:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div dir="ltr">Am Mi., 15. Jan. 2020 um 09:13 Uhr schrieb Thiede, Christoph <<a href="mailto:Christoph.Thiede@student.hpi.uni-potsdam.de" target="_blank">Christoph.Thiede@student.hpi.uni-potsdam.de</a>>:<br>
</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div id="gmail-m_2472782000106643763gmail-m_2847815226910863130divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<div id="gmail-m_2472782000106643763gmail-m_2847815226910863130divtagdefaultwrapper" dir="ltr">
<p style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:12pt">
<span style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt">You proposed using a promise - I never had the pleasure to meet them until today. Maybe you have a minimum working example for demonstrating your proposal? FutureNodes seem to be used very
 rarely in Trunk :-)</span></p>
</div>
</div>
</div>
</blockquote>
<div>I have no minimum example ready, but here is the outline:</div>
<div>- Add an instance variable for the promise to the model.</div>
<div>- Initialize with `Promise new` when the model is asked to open a view.</div>
<div>- Answer the promise to the open message.</div>
<div>- In the model's method that is invoked when the dialog is accepted, promise resolveWith: theResultOfWhatHappened</div>
<div>- In the method that opens the tool, take the promise and use whenResolved:, whenRejected: (handle the outcome) or then:ifRejected: (handle the outcome and answer another promise -- chaining). Do not attempt to return from the handler blocks, the method
 will have returned by the time they are evaluated.</div>
<div><br>
</div>
<div>Of course it is a totally different style of programming than with modal windows.</div>
<div><br>
</div>
<div>Similar alternative without promises:</div>
<div>- Instead of a promise, store a MessageSend in the model.</div>
<div>- In the client of the model, store all necessary state to continue in instance variables.</div>
<div>- Do not expect a return value from opening the view for the model.</div>
<div>- Have the model send the message to self upon continuation.</div>
</div>
</div>
</blockquote>
</div>
</div>
</body>
</html>