darrenhillconsulting
03/07/2022, 10:03 PMrecord.create.promise
in a restlet? Meaning .. I want to capture the incoming payload in a custom record, but also want to return a 200 as a response as quickly as possible (since the status of the operation isn't needed in the response)Shawn Talbert
03/07/2022, 10:12 PMGerald Gillespie
03/07/2022, 10:12 PMdarrenhillconsulting
03/07/2022, 10:13 PMdarrenhillconsulting
03/07/2022, 10:13 PMcreece
03/07/2022, 10:14 PMdarrenhillconsulting
03/07/2022, 10:14 PMdarrenhillconsulting
03/07/2022, 10:15 PMcreece
03/07/2022, 10:18 PMcreece
03/07/2022, 10:19 PMdarrenhillconsulting
03/07/2022, 10:20 PMdarrenhillconsulting
03/07/2022, 10:22 PMdarrenhillconsulting
03/07/2022, 10:22 PMdarrenhillconsulting
03/07/2022, 10:23 PMShawn Talbert
03/07/2022, 11:03 PMShawn Talbert
03/07/2022, 11:04 PM.then
and see if it ever makes it to the execution logShawn Talbert
03/07/2022, 11:06 PMabout to return from the restlet
, return your JSON response, then log something in that promise handler (made it to the handler
) If you don't get both messages then you know that promise handler was never called?darrenhillconsulting
03/07/2022, 11:56 PMdarrenhillconsulting
03/07/2022, 11:57 PMrecord.
promises are not supported server-side (RESTlet). ... so @Shawn Talbert, you're right! (And I'm sad)Shawn Talbert
03/07/2022, 11:59 PMShawn Talbert
03/08/2022, 12:00 AMdarrenhillconsulting
03/08/2022, 12:04 AMpromise
and not only did it run, but ran successfully.darrenhillconsulting
03/08/2022, 12:05 AMdarrenhillconsulting
03/08/2022, 12:05 AMdarrenhillconsulting
03/08/2022, 12:08 AMShawn Talbert
03/08/2022, 12:55 AMShawn Talbert
03/08/2022, 12:57 AMShawn Talbert
03/08/2022, 12:57 AMShawn Talbert
03/08/2022, 3:57 PM.then()
on your promise never gets invoked sever-side?darrenhillconsulting
03/08/2022, 4:11 PMGerald Gillespie
03/08/2022, 5:13 PMN/record
and no api…..YET.
Behind the scenes (outside the JS REPL) an operation like reading a record from the database might benefit from offloading that via threading but it has to be implemented that way. NetSuite doesn’t tell us where these optimizations have been made but there are clues such as promises being available in the api. So it seems to have been done for search and query and web requests. If you really wanted it to be a promise /async structure you could wrap it in a promise. c.p. there’s no performance benefit to it on the server-side.
let’s say they were planning on having internal optimization for N/record. Then making a promise method available would make sense. You could write code today that does not perform better but logically expects it to be asynchronous. When it becomes asynchronous then you get the benefit automatically without a re-write.
in short,
Today you could stick record.create
into a promise simply with Promise.resolve(record.create({options}))
hypothetically if record.create.promise becomes available on the server side you can rewrite that one line to take advantage and logically everything would still flow.
if you’re feeling optimistic or have some insider knowledge, you could have your stub or proxy for it. Logically equivalent to this ugliness:
Promise.resolve((create=>create({options}))(record.create.promise || record.create)).then(/*etc*/)
i’m not suggesting you should do this — simply trying to keep the neurons firing.Shawn Talbert
03/08/2022, 5:21 PM