Code Monkey home page Code Monkey logo

Comments (3)

gfwilliams avatar gfwilliams commented on August 22, 2024

Eurgh. Ok, thanks. This'll be because of #2454

Stuff like this in BLE is done with blePromise = jspromise_create(); and then to complete we do jspromise_resolve(blePromise, data); or similar.

But looking at this, jspromise_create just creates an empty object you've called box, so it's not a promise and nothing like .then could be used with it?

So I'm not sure how this can really work as-is... @d3nd3 any thoughts?

I guess maybe you assumed jspromise_create wasn't used outside so changed what it does? While we could just return the promise like jswrap_promise_constructor does, then the box is just not referenced at all and freed immediately which seems like it's not the plan?

from espruino.

d3nd3 avatar d3nd3 commented on August 22, 2024

@gfwilliams I was aware of jspromise_create() usage outside, I thought its fine since I made the resolve/reject functions take a prombox instead of a promise, but if they are returning the promise to javascript usercode it has to be adjusted to return the child promise which it contains.

JsVar *promise = jsvLockAgainSafe(blePromise);
  jsble_central_getPrimaryServices(jswrap_ble_BluetoothRemoteGATTServer_getHandle(parent), uuid);
  return jsvObjectGetChildIfExists(blePromise, JS_HIDDEN_CHAR_STR"prom");

Can you validate the locks? Not my speciality.

Mb its good practise if we name the variables prombox to make it clear also. Box is just a naming for container. Also, are there any other functions which return a promise like this?

#2454

from espruino.

gfwilliams avatar gfwilliams commented on August 22, 2024

In the code snippet above, I'm not sure what's going on with JsVar *promise = jsvLockAgainSafe(blePromise); lock-wise, but in the actual PR as far as I could tell the locks seemed ok (and the tests do check for dangling locks, so the fact they pass is a good sign).

Also, are there any other functions which return a promise like this?

A few I think - it's any Espruino function that creates and returns something to the user - so off the top of my head, the bluetooth connect (maybe disconnect), write, startNotifications, then on Bangle we've got beep, buzz, pressure. etc.

Basically it's a pretty big bunch of changes. I'll try and reply properly in #2454

from espruino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.