Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply async functionality to client library #25

Open
5 of 6 tasks
barabo opened this issue Jun 2, 2021 · 4 comments
Open
5 of 6 tasks

Apply async functionality to client library #25

barabo opened this issue Jun 2, 2021 · 4 comments
Assignees
Labels
lib Issue affecting only the client library code.

Comments

@barabo
Copy link
Owner

barabo commented Jun 2, 2021

  • swm.sendMessage('customEHR.watchClicks', {...payload}) - handle a stream of responses via generator
  • swm.createClient - creates a client object using the messaging handle and target origin
  • client.sendMessage('status.handshake') - or any other known types. returns a promise.
  • client.sendResponseTo(message) - reads the messageId and sets responseToMessageId
  • use new client in app and ehr
  • swm.discover() - returns library details
@barabo barabo self-assigned this Jun 4, 2021
@barabo barabo pinned this issue Jun 4, 2021
@barabo barabo added the lib Issue affecting only the client library code. label Jun 4, 2021
@barabo
Copy link
Owner Author

barabo commented Jun 4, 2021

See sketched api here: https://hackmd.io/@jmandel/HyxB7yV9_/edit

@barabo barabo linked a pull request Jun 7, 2021 that will close this issue
4 tasks
@barabo
Copy link
Owner Author

barabo commented Jun 7, 2021

FWIW: some of the incorporated async ideas came from this:
https://stackoverflow.com/questions/26150232/resolve-javascript-promise-outside-function-scope

@barabo barabo removed a link to a pull request Jun 7, 2021
4 tasks
@barabo
Copy link
Owner Author

barabo commented Jun 8, 2021

The lib user docs are being tracked in issue #51

@barabo
Copy link
Owner Author

barabo commented Jun 10, 2021

To add detail to the remaining desired async functionality, consider this use pattern:

const clicks = client.getMessageResponse("customEHR.watchUserClicks", {...payload});

for await (let click of clicks.generator) { /// async generator syntax... something kinda like this
  console.log("User clicked at", click);
  if (click.x === click.y) {     // because *of course* we're building a y===x detector app...
      clickGenenerator.cancel(); // unregister a promise or generator
                                 // so the client can free up memory
      break; // technically
  }
  console.log("Waiting for another click...")
}

This behavior has not been described by the IG, but it has been discussed as a favorable pattern and specifically encouraged for further experimentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib Issue affecting only the client library code.
Projects
None yet
Development

No branches or pull requests

1 participant