91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

SAP Cloud for Customer里Promise的實際應用場合是怎樣的

發布時間:2021-12-29 19:25:37 來源:億速云 閱讀:125 作者:柒染 欄目:互聯網科技

這篇文章將為大家詳細講解有關SAP Cloud for Customer里Promise的實際應用場合是怎樣的,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。

最近,我正在研究SAP Cloud for Customer的前端代碼,我遇到了一個如何在那里使用promise的真實示例。下面是密碼登錄視圖。

SAP Cloud for Customer里Promise的實際應用場合是怎樣的

Once Passcode is entered, suppose I have already entered the system url and frontend user name in the past, they will be directly retrieved from browser storage.

SAP Cloud for Customer里Promise的實際應用場合是怎樣的

Currently I use Chrome to access C4C and Web SQL is used as browser storage, where the system url and logon user name could be found from Chrome development tool.

SAP Cloud for Customer里Promise的實際應用場合是怎樣的

The corresponding database initialization and table read is done by code below in file AppStatusService.js.

The series of callback functions are chained by promise API “then()” which are expected to be executed sequentially:

(1) _createTable() could only be executed after database initialization is done. (2) _getApplicationStatus could NOT be executed unless the database table which stores Application status is available – this is ensured by _createTable. (3) After application status is read from database table, _createDefaultEntries could be called to render the default value in Passcode logon view.

SAP Cloud for Customer里Promise的實際應用場合是怎樣的

All above three steps are organized by promise to achieve the asynchronous execution mode. In order for me to understand how the above code works, I write a simplified version for illustration:

<!doctype html><html><head><script>var end;function setupDB(){
    return this.createDatabase().then(createTable).then(insertEntry).then(readEntry).then(printResult);}function createTable(){
    return new Promise(function(resovle, reject) {
        console.log("prepare to create table..." + Date.now());
        this._db.transaction(function(query){
            query.executeSql('create table if not exists user(id unique, user, passwd)');
        });
        setTimeout( _createTableOK.bind(this, resovle), 1000);
    });}function _createTableOK(resovle){
    console.log("table created successfully..." + Date.now());
    resovle();}function createDatabase(){
    return new Promise(function(resovle, reject) {
        console.log("prepare to create database..." + Date.now());
        this._db = openDatabase('mydb','1.0', 'JerryTestdb',1024);
        setTimeout( _createDatabaseOK.bind(this, resovle), 1000);
    });}function _createDatabaseOK(resovle){
    console.log("database created successfully..." + Date.now());
    resovle(this._db);}function insertEntry(){
    return new Promise(function(resolve, reject) {
        this._db.transaction(function(query){
            query.executeSql("insert into user values (1,'Jerry','1234')");
        });
        setTimeout( _insertEntryOK.bind(this, resolve), 1000);
    });}function _insertEntryOK(resolve){
    console.log("entry inserted to table successfully..." + Date.now()); 
    resolve();}function readEntry() {
    return new Promise(function(resolve, reject) {
            this._db.transaction( function(query) {
                query.executeSql('select * from user',[],function(u,results) {
                setTimeout( _readEntryOK.bind(this, resolve, results), 1000);
            }); // end of query.executeSql     } // end of function(query)     ); // end of this._db.transaction });}function _readEntryOK(resolve, oResult){
    console.log("entry readed from DB successfully..." + Date.now());
    resolve(oResult);}function printResult(oResults){
    for( var i = 0; i < oResults.rows.length; i++) {
            document.writeln('id: ' + oResults.rows[i].id);
            document.writeln('user: ' + oResults.rows[i].user);
            document.writeln('passwd: ' + oResults.rows[i].passwd);
    }
    end = true;}function work(){
    if( end ){
        clearInterval(handle);
    }
    else{
        console.log(" working..." + Date.now());
    }}setupDB();var handle = setInterval( work, 200);</script></head></html>

Open the html page with Chrome, and you can find that a database with name mydb and a table user is created with one record inserted.

SAP Cloud for Customer里Promise的實際應用場合是怎樣的

In order to achieve the simulation that each step of webSQL is a time-consuming operation, I wrap the real logic into setTimeout with a certain time delay.

I scheduled function work to simulate the main work to do and the database related job are done in an asynchronous way organized within function module setupDB() by promise API.

SAP Cloud for Customer里Promise的實際應用場合是怎樣的SAP Cloud for Customer里Promise的實際應用場合是怎樣的

The console output proves that the database operations are really executed asynchronously in exactly the same order as they are scheduled via then API of promise.

SAP Cloud for Customer里Promise的實際應用場合是怎樣的

Note

Not all browsers support WebSQL and the specification of WebSQL is no longer in active maintenance.

SAP Cloud for Customer里Promise的實際應用場合是怎樣的

Even in C4C frontend framework code we can see more and more usage on IndexedDB instead:

SAP Cloud for Customer里Promise的實際應用場合是怎樣的

關于SAP Cloud for Customer里Promise的實際應用場合是怎樣的就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

东平县| 乾安县| 嘉黎县| 进贤县| 通州区| 麻栗坡县| 岳池县| 纳雍县| 长武县| 宁乡县| 阿拉善右旗| 信丰县| 固阳县| 宾阳县| 砀山县| 威远县| 视频| 新丰县| 景泰县| 防城港市| 河东区| 扎鲁特旗| 四川省| 云龙县| 博客| 航空| 蒲城县| 瑞丽市| 益阳市| 镇原县| 德江县| 荆门市| 兴化市| 兴和县| 广安市| 莲花县| 芷江| 汉寿县| 连云港市| 庄浪县| 抚远县|