tglogo.png
0 LIKES

Snippet


Download methods by xorc

In Category General IRC Posted by Snippets On 12/07/23
Tags: download xorc 

v2 Signal polling microsoft.xmlhttp (COM):
Calls microsoft.xmlhttp comobject asynchronous and dispatches a signal to check the result, which if isn't done yet signals itself again until the response is received, then calls the provided callback when the contents is written to disk.

Performance / Example:
//echo ticks: $ticks | /XMLHTTPRequest "echo ticks: $($ticks,0) result:" http://www.google.com/ google.html
time: 12:57:24 ticks: 51840640
time: 12:57:24 ticks: 51840687 result: XMLHTTPRequest1393273344 $true http://www.google.com/ google.html
Elapsed 47 ticks
alias XMLHTTPRequest {

  var %callback = $1
  var %URI = $2
  var %path = $3

  if (" isin $1) {
    var %callback = $mid($1-,1,$pos($1-,",2))
    var %args = $replace($1-,%callback,)
    tokenize 32 %args
    unset %args

    var %callback = $noqt(%callback)
    var %URI = $1
    var %path = $2
  }

  var %comid = $+(XMLHTTPRequest,$hash($nopath(%path),32))

  if ($com(%comid)) .comclose %comid
  .comopen %comid microsoft.xmlhttp

  noop $com(%comid,Open,4,bstr,GET,bstr,%URI,bool,1)
  noop $com(%comid,Send,1)

  $+(.,timer,%comid) 1 0 .signal -n %comid $qt(%callback) %URI %path
  $+(.,timer,%comid,timeout,timer) 1 10 .timer $+ %comid off 
  $+(.,timer,%comid,timeout,com) 1 10 .comclose %comid
}

on *:SIGNAL:XMLHTTPRequest*: {

  var %comid = $signal
  var %callback = $1
  var %URI = $2
  var %path = $3

  if (" isin $1) {
    var %callback = $mid($1-,1,$pos($1-,",2))
    var %args = $replace($1-,%callback,)
    tokenize 32 %args
    unset %args

    var %callback = $noqt(%callback)
    var %URI = $1
    var %path = $2
  }

  goto $com(%comid,responseText,2)

  :-1 | %callback %comid $false %URI %path | halt
  :0 | $+(.,timer,%comid) 1 0 .signal -n %comid $qt(%callback) %URI %path | halt
  :1
  $+(.,timer,%comid,*) off

  bwrite $5 0 $com(%comid,&binvar).result &binvar

  .comclose %comid

  %callback %comid $true %URI %path
}


Comments 0


Please note that on our website we use cookies necessary for the functioning of our website, cookies that optimize the performance. To learn more about our cookies, how we use them and their benefits, please read our Cookie Policy.
I Understand