Skip to content

Commit

Permalink
Add 开门grab、take
Browse files Browse the repository at this point in the history
  • Loading branch information
E0SelmY4V committed Jan 20, 2023
1 parent 1e5a103 commit a5a10df
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ declare namespace scpoProce {
function then<RT, E1 extends readonly any[] = [any]>(todo?: CbNor<[], RT, any[]>, ordo?: CbNor<[]>): Proce<[RT], E1>
function trap(ordo?: CbNor<[]>): Proce<[], []>
function next<P1 extends readonly any[], E1 extends readonly any[]>(doexpr?: CbNxt<P1, [], E1>, ordo?: CbNor<E1, any, any[]>, config?: Config): Proce<P1, E1>
function take(depth?: number): Proce<[], []>
function take<RT, E1 extends readonly any[] = [any]>(todo?: CbNor<[], RT, any[]>, ordo?: CbNor<[]>, depth?: number): Proce<[RT], E1>
function grab<P1 extends readonly any[], E1 extends readonly any[]>(doexpr?: CbNxt<P1, [], E1>, ordo?: CbNor<E1, any, any[]>, depth?: number, config?: Config): Proce<P1, E1>
function conf<E1>(config?: Config, ordo?: CbNor<[], E1, any[]>): t.cp<[], E1>
function configAll(): Proce<[], []>
function todo<A extends Accur<A>, P1 extends A[]>(...n: P1): Proce<P1, []>
Expand Down
3 changes: 3 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
return cf.hidden = true, this.then(cf, ordo), proc.before = this, proc.trap(ordo);
},
take: function (todo, ordo, depth) {
if (!this.id) return new Proce(null, null, true).take(todo, ordo, depth);
typeof todo === 'number' ? (depth = todo) : (typeof depth === 'undefined' || depth === null) && (depth = -1);
var _this = this, testf, proc = new Proce(function (todo, ordo) {
_this.then(testf = function (rtn) {
Expand Down Expand Up @@ -292,6 +293,8 @@
'then',
'trap',
'next',
'take',
'grab',
'conf',
'configAll',
'todo',
Expand Down
24 changes: 16 additions & 8 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../global.d.ts" />
const scpoProce = require('scpo-proce');
const https = require('https');
const webReq = (url, callback) => https.get(url, res => {
const list = [];
Expand All @@ -8,7 +8,7 @@ const webReq = (url, callback) => https.get(url, res => {
const { testWebsite } = require('./tool');
const alert = console.log;
const test = {
['错误捕获']() {
'错误捕获'() {
const a = scpoProce((res, rej) => setTimeout(res, 200))
.then(() => a(345))
.then(() => alert(234), () => alet(123))
Expand All @@ -17,24 +17,24 @@ const test = {
.then(() => a(432));
return a.trap(() => alert(543));
},
['多参数回调网络请求']() {
'多参数回调网络请求'() {
return scpoProce(todo => webReq(testWebsite + "?=" + Math.random(), todo))
.then((data, w) => alert(data + w));
},
['开门then']() {
'开门then'() {
return scpoProce()
.then(() => (alert("hh"), testWebsite + "?=" + Math.random()))
.next((todo, ordo, url) => webReq(url, todo))
.then((data, w) => alert(data + w));
},
['snake方法']() {
'snake方法'() {
return scpoProce.snake(
(todo) => todo(testWebsite + "?=", Math.random()),
(todo, ordo, url, randNum) => webReq(url + randNum, todo),
(todo, ordo, data) => alert(data),
);
},
['配置默认回调']() {
'配置默认回调'() {
// scpoProce.configAll({
// todo: function (d) { alert(d); },
// ordo: function () { alert('err!'); }
Expand All @@ -43,16 +43,24 @@ const test = {
.conf({ todo: () => alert(123) });
return scpoProce(res => setTimeout(res, 1500));
},
['all方法']() {
'all方法'() {
return scpoProce.all(
scpoProce((todo) => setTimeout(todo, 1000)).then(() => 123),
scpoProce((todo) => setTimeout(() => todo(234), 2000)),
).then((rslt) => alert(rslt));
},
'开门take'() {
alert(scpoProce.take(0));
alert(scpoProce.take());
alert(scpoProce.take(() => 123));
},
'开门grab'() {
return scpoProce.grab(todo => setTimeout(todo, 1000)).then(() => alert(123));
},
};
module.exports = async () => {
for (const i in test) {
console.group(i);
console.log('\033[43m ' + i + ' \033[0m');
await test[i]().then(() => (
console.groupEnd(i),
console.log('')
Expand Down

0 comments on commit a5a10df

Please sign in to comment.