草庐IT

index-async

全部标签

javascript - Async/Await with Request-Promise 返回 Undefined

我有两个文件;server.js和scrape.js,下面是它们当前的代码片段。服务器.js:constscrape=require("./scrape");asyncfunctionstart(){constresponse=awaitscrape.start();console.log(response);}start();和scrape.js:constcheerio=require("cheerio");constrequest=require("request-promise");go=async()=>{constoptions={uri:"http://www.somew

javascript : Async/await in . 替换

我正在按以下方式使用async/await函数asyncfunction(){letoutput=awaitstring.replace(regex,async(match)=>{letdata=awaitsomeFunction(match)console.log(data);//givescorrectdatareturndata})returnoutput;}但是返回的数据是一个promise对象。只是对它应该在带有回调的此类函数中实现的方式感到困惑。 最佳答案 一些异步替换的易于使用和理解的函数:asyncfunctionr

javascript - Babel - 使用 transform-async-to-generator 插件时未定义 regeneratorRuntime

我无法正确设置babel以使用async/await。我正在使用babel7和webpack4。如果可能,我不想使用babel-polyfill!我的babelrc文件:{"presets":[["@babel/env",{"modules":false}]],"plugins":["syntax-dynamic-import","transform-async-to-generator"]}代码:asyncfunctioninit(){constloaderData=awaitinitLoader();initCmp(loaderData).then(initApi(loaderDa

javascript - 使用 index.ts 文件导出类导致注入(inject)的构造函数中未定义

我使用index.ts文件来封装导出,如Angular2样式指南(https://github.com/mgechev/angular2-style-guide/blob/master/old/README.md#directory-structure)中所述。这在我编写的应用程序中运行良好,但出于某种原因,在我尝试注入(inject)另一项服务的一项服务中,这会导致奇怪的错误。导出类:import{Injectable}from"angular2/core";@Injectable()exportclassUserIds{private_signature_id:string;pri

javascript - 为什么 z-index 不能在 Chrome 中使用 CSS 列?

我使用column-count创建的多列布局的z-index有问题。我想使用.animate()将单击的div移动到列表顶部,但是当我单击右列中的元素时,它会位于左列元素的后面。这在Firefox上运行良好,但在Chrome上不起作用。有什么想法吗?functiongotoTop(element){vardestinationTop=$('.categories').offset().top;varelementOffsetTop=$(element).offset().top;vardistanceTop=(elementOffsetTop-destinationTop);retur

javascript - JS async/await - 为什么 await 需要异步?

为什么使用await需要将其外部函数声明为async?例如,为什么这个mongoose语句需要它所在的函数来返回一个promise?asyncfunctionmiddleware(hostname,done){try{letteam=awaitTeams.findOne({hostnames:hostname.toLowerCase()}).exec();done(null,team);}catch(err){done(err);}}我看到运行时/转译器将Teamspromise解析为它的值(value),并发出异步信号它“抛出”被拒绝的promise。但是try/catch会“捕获”

string - 无法在字符串 : "cannot use <xxx> (type <yyy>) as type string in map index" 的映射中使用基础类型的字符串

这个问题在这里已经有了答案:ConvertingacustomtypetostringinGo(4个答案)关闭3年前。我有底层字符串类型:typeCapabilitystring。我想将它用作字符串映射中的字符串,但出现错误:cannotusecap(typeCapability)astypestringinmapindex这是我的代码:packagemainimport("fmt")typeCapabilitystringvarcaps_list=map[string]int{"HOME":1,}funcmain(){varcapCapability//stringcap="HOME

Go 库 - golang 的 async.auto

在Nodejs中,我们有async.auto(http://caolan.github.io/async/docs.html#.auto),它通过拓扑排序自动管理扇出顺序。Go中是否有类似的库来管理您的请求顺序 最佳答案 你可以试试这个:https://github.com/kamildrazkiewicz/go-flow它基于channel排空(async.auto使用拓扑排序)但它的工作方式类似。 关于Go库-golang的async.auto,我们在StackOverflow上找到

go - panic : runtime error: index out of range [recovered]

在将ifj==len(remark)修改为ifj==len(remark)&&z>0之后,我的代码出现了panic错误错误是:---FAIL:TestHey(0.00s)panic:runtimeerror:indexoutofrange[recovered]panic:runtimeerror:indexoutofrangegoroutine5[running]:testing.tRunner.func1(0xc04207a0f0)C:/Go/src/testing/testing.go:711+0x2d9panic(0x526700,0x5f57c0)C:/Go/src/runti

golang 运行时错误 : index out of range

我在go中有一个简单的for循环,它遍历一个整数片段并更改当前位置,如果下一个更小,基本上是一种排序,但它一直向我显示这个错误,上面写着panic:runtimeerror:indexoutofrange代码如下:funcsort(nint,l[]int)interface{}{fmt.Println(l)ifd==false{d=truefori:=rangel{n:=i+1t:=l[i]l[i]=l[n]l[n]=tarr=ld=false}returnsort(n,arr)}returnarr}返回的arr声明为全局变量。这是错误:panic:runtimeerror:index