gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain5d144817Merge branch 'records-t40' into mainTicketsmain/tests/events-client.hl

1.2 KB

  1. // tests/events-client.hl — a PROGRAM subscribing to GET /api/events with hl:fetch's stream mode (ticket #26): prints
  2. // one line `EVENT <json>` per event and stops after EVENTS_MAX of them. tests/events.mjs runs it; it is also the
  3. // smallest example of a Hybriel subscriber.
  4. // EVENTS_URL=http://127.0.0.1:8790/api/events?project=alpha EVENTS_TOKEN=tkt_… EVENTS_MAX=2 ./bin/hybriel tests/events-client.hl
  5. import { fetch, fetchAbort } from 'hl:fetch'
  6. import { env } from 'hl:proc'
  7. url = env('EVENTS_URL')
  8. max = env('EVENTS_MAX') != null ? toNumber(env('EVENTS_MAX')) : 1
  9. let seen = 0
  10. let rest = ''
  11. p = fetch(url, { headers = { 'Authorization' = 'Bearer ' + env('EVENTS_TOKEN') } stream = true tag = 'events' })
  12. console.log('OPEN')
  13. on p.chunk({ chunk }) {
  14. rest = rest + chunk
  15. let at = rest.indexOf('data: ')
  16. while (seen < max && at >= 0 && rest.indexOf(newline, at) > at) {
  17. end = rest.indexOf(newline, at)
  18. console.log('EVENT ' + rest.slice(at + 6, end))
  19. seen = seen + 1
  20. rest = rest.slice(end + 1)
  21. at = rest.indexOf('data: ')
  22. }
  23. if (seen >= max) { fetchAbort('events') }
  24. }
  25. on p.done({ status }) { console.log('DONE ' + status) }
  26. // the language has no escapes: a newline is written as itself
  27. static newline = "
  28. "

Branches

Latest commits

  • 5d144817Merge branch 'records-t40' into mainTickets
  • 44ee6f06|||PR records: #43 #45 livemre
  • b8fdeee9Merge branch 'p39-routes' into mainTickets
  • a0187a0a|||PR Remove redundant route-order loopmre
  • 369e4b9cMerge branch 'k40-lists' into mainTickets
  • 9af8e780|||PR Use keyed list mutations for live ticket updatesmre
  • 610d8e8aMerge branch 'records-t39' into mainTickets
  • 32bcdf24|||PR records: GO P39 K40mre
  • 4123c6d1Merge branch 'records-t38' into mainTickets
  • cd3641a1|||PR records: day72 deploy live, tickets closedmre
  • 7d44d852Merge branch 'records-t37' into mainTickets
  • 926f7061|||PR records: merges, D36 deploymre
  • bf58534eMerge branch 'l33-final' into mainTickets
  • 759a9ac3|||PR thin login (tickets#46, #45): merge main, route entry cleanupmre
  • 239436d8Merge remote-tracking branch 'origin/main' into l33-finalmre
  • 5822cb3aMerge branch 'o34-clean' into mainTickets
  • 0870653c|||PR offline note from __hlOnline, no polling (tickets#41)mre
  • 14cf96b4Merge branch 'records-t36' into mainTickets
  • 07749fa1|||PR records: day72 + #40 mergedmre
  • ecd7e226|||PR Consolidate login and move handler logic into topic libraries (partial)mre