Comments (3)
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.
@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?
from espruino.
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)
- Wifi.connect(ssid, options, callback) does not handle callback HOT 2
- Multiple uploads of code with wifi command can cause " New interpreter error" HOT 1
- Debugger feature: add backtrace command HOT 2
- E.getPowerUsage to estimate power consumption HOT 2
- BLE/NRF and esp32_gatts_func.c HOT 1
- ESP32_IDF4 (ESP32C3) support HOT 4
- Any plans to switch to python3? HOT 5
- `Object.defineProperty(<function>, ...)` HOT 1
- `Object.clone()` returning function HOT 2
- Using different pins for neopixel on ESP32 does not work correct HOT 1
- Loss of errors when executing require() HOT 4
- banglejs_iflash build: error running `.bootcde`, compacting corrupts `.boot0` and deletes most files HOT 4
- Static fields in classes HOT 1
- Bad text alignment when rendering Unicode centered
- overlays are cut off from the top instead of landing at desired y position HOT 2
- [Bangle.js 2 Question] EXTCOM frequency HOT 1
- nrf5x_dfu/main.c highlight potential impossible code path HOT 2
- Scoping bug when defining a function from a previous scope HOT 14
- Stuck uploading firmware v23 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from espruino.