[Ur] redirect breaks channels

Sergey Mironov grrwlf at gmail.com
Tue Dec 24 16:54:36 EST 2013


Hi.
I've faced a channel issue. Looks like I can't put a value into a
channel from the transaction which didn't create that channel using
`channel' function. Consider the following program:

table t : { Id : int , Chan : channel int }

fun put (i:int) =
    r <- oneRow1(SELECT * FROM t WHERE t.Id = 0);
    Basis.send r.Chan i

fun monitor {} : transaction page =
  r <- oneRow1(SELECT * FROM t WHERE t.Id = 0);
  ch <- return r.Chan;
  let
      fun ping () =
        i <- recv ch;
        alert (show i);
        ping ()
  in
      return
       <xml>
        <body onload={ping ()}>
          <button value="Send a value" onclick={fn x => rpc (put 33)}/>
        </body>
       </xml>
  end

fun main () : transaction page =
    ch <- channel;
    dml(INSERT INTO t (Id,Chan) VALUES (0,{[ch]}));
    redirect (url (monitor ()))


The monitor here doesn't receive any messages from the channel,
despite the fact that there is only one channel in the database. But
if I move
    ch <- channel; dml(INSERT INTO t (Id,Chan) VALUES (0,{[ch]}));
lines from main to the monitor's body, everything works. Please
suggest a fix/workaround!

Merry christmas to all

Sergey

PS

Application reports
Begin error: cannot start a transaction within a transaction<br
/>Expunge blocked by error: Error running SQL BEGIN
Note, I'm using sqlite engine. I've tried it using vanilla urweb too:)
The source is in attach.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: channel2.ur
Type: application/octet-stream
Size: 638 bytes
Desc: not available
URL: <http://www.impredicative.com/pipermail/ur/attachments/20131225/a05f47d5/attachment.obj>


More information about the Ur mailing list