Code Monkey home page Code Monkey logo

deno_note's Introduction

Hi there 👋

profile views

I am the creator of the open source JavaScript framework iDraw.js.

You can click @idraw/studio to experience the use of iDraw.js .

If you think my project is helpful to you, just give me a cup of coffee!

Buy Me A Coffee


大深海,野生程序员一枚,闲暇时讲点技术的故事。

deno_note's People

Contributors

chaslui avatar chenshenhai avatar kennytian avatar melodyvoid avatar unbyte avatar xcatliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deno_note's Issues

需要升级到v0.7.0

原有demo和教程是基于[email protected]

  • 在v0.4.0 以后,官方支持了子命令,执行方式变了,原有demo全部跑不动了 o(╯□╰)o
  • Deno原生指令使用方式做了重构,需要重新梳理笔记教程

在没完成升级v0.7.0之前,不建议直接git clone 学习。
如果想跑起所有demo案例,必须保证在[email protected]的环境里

逐步替换 import "deno"成全局Deno变量

[email protected] 已经支持全局变量Deno,Deno官方声明了未来的版本将不会兼容 import deno from "deno" 的方式,后续笔记例子源码需要全面替换修改。

官方v0.3.0 说明
The major API change in this release is that instead of importing a "deno" module, there is now a global variable called Deno. This allows code that does deno-specific stuff to still operate in browsers. We will remain backward compatible with the old way of importing core functionality, but it will be removed in the near future, so please update your code.

https://github.com/denoland/deno/blob/master/Releases.md#v030--20190218

这样是不是更好?

async readLine(): Promise<string> {
        // 每一行初始数据为0字节
        let lineBuf = new Uint8Array(0);
        
        while (!this._eof || this._chunk.length > 0) {
            // 获取总区块的数据
            const current = this._current;
            // 循环已读chunk中是否存在换行符号 可以优化
            // for (let i = 0; i < current.byteLength; i++) {
            //     if (current.byteLength <= 0) {
            //         continue;
            //     }
                const buf = current.subarray(this._chunk.length-2, this._chunk.length -1);
                if (this._isCRLF(buf) === true) {
                    lineBuf = current.subarray(0, this._chunk.length-3);
                    this._currentReadIndex = this._chunk.length -1;
                    return decoder.decode(lineBuf);
                }
            // }
            //每次循环之后读取字符
            const result = await this._readChunk();


            if (!result) {
                break;
            }
        }

windowapi 只打印出19个

代码

const apiList = Object.keys(window)
const CRLF = '\r\n'
console.log(`Supported global Api[count:${apiList.length}]:${CRLF}`);
console.log(`${apiList.join(','+CRLF)}`)

版本和执行结果

➜  denodemo deno --version         
deno 0.36.0
v8 8.1.310
typescript 3.8.3
➜  denodemo deno run ./src/showwindow.ts 
Supported global Api[count:19]:

console,
Deno,
queueMicrotask,
atob,
btoa,
clearInterval,
clearTimeout,
fetch,
setInterval,
setTimeout,
performance,
addEventListener,
dispatchEvent,
removeEventListener,
window,
self,
crypto,
onload,
onunload

考虑使用 pagic 来搭建网站吗?

要不要使用 Pagic 搭建一个网站?若 @chenshenhai 同意的话,我可以帮忙完成第一版的工作😊

Pagic 是用 Deno 实现的一个静态网站生成器,这是第一个使用 Pagic 搭建的网站:
https://ts.xcatliu.com/

特性:

  • github actions 持续集成发布
  • 静态网页 + 单页应用——页面初次加载性能最优,页面间跳转时能无缝跳转
  • 深色模式
  • gitalk 评论
  • 更多功能开发中

这是第二个使用 Pagic 搭建的网站:
https://deno-tutorial.js.org/

deno example.ts 报错

➜ Deno $ deno example.ts

⚠️ Deno requests network access to "127.0.0.1:3001". Grant? [a/y/n/d (a = allow always, y = allow once, n = deny once, d = deny always)] a
listening on 127.0.0.1:3001
thread 'tokio-runtime-worker-0' panicked at 'bad rid', ../../cli/resources.rs:273:15
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace.
thread 'main' panicked at 'internal error: entered unreachable code', ../../third_party/rust_crates/registry/src/github.com-1ecc6299db9ec823/tokio-0.1.22/src/runtime/threadpool/mod.rs:296:26
thread 'main' panicked at 'unexpected state while aborting task: Complete', ../../third_party/rust_crates/registry/src/github.com-1ecc6299db9ec823/tokio-threadpool-0.1.15/src/task/mod.rs:216:21
stack backtrace:
0: 0x1075ad062 - std::panicking::take_hook::hb25650a43c7b4abc
1: 0x1075acd2b - std::panicking::take_hook::hb25650a43c7b4abc
2: 0x1075ad850 - std::panicking::rust_panic_with_hook::h7d6a669f1a899680
3: 0x1075ad37d - std::panicking::begin_panic_fmt::h5340abefa09e06ca
4: 0x1075ad2d1 - std::panicking::begin_panic_fmt::h5340abefa09e06ca
5: 0x1085265d9 - tokio_threadpool::pool::backup_stack::<impl core::convert::From<tokio_threadpool::pool::backup_stack::State> for usize>::from::h22f244c8801cbba7
6: 0x10852e7af - <tokio_threadpool::shutdown::ShutdownTrigger as core::ops::drop::Drop>::drop::h134c463c5ff9ac9e
7: 0x10852aafc - <tokio_threadpool::task::Run as core::fmt::Debug>::fmt::h6b791071bd8e3ab7
8: 0x108521a9a - tokio_threadpool::thread_pool::ThreadPool::shutdown_now::h6c753972452ea1f4
9: 0x1084fed0d - tokio::runtime::current_thread::runtime::Runtime::run::h9d7c951fd5cdd0a1
10: 0x1085026a8 - <tokio::runtime::threadpool::Runtime as core::ops::drop::Drop>::drop::h0fc176c521b72182
11: 0x1087cb1bc - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
12: 0x1088c2368 - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
13: 0x1087b7e46 - <arc_swap::Protection as core::convert::From<core::option::Option<&arc_swap::debt::Debt>>>::from::h427ca8060d312f50
14: 0x1075ad1e8 - std::panicking::update_panic_count::hb4c719f9cf8762c5
15: 0x1075bcc4f - __rust_maybe_catch_panic
16: 0x1075adcce - std::rt::lang_start_internal::hc1ac2c20e9f8edf2
17: 0x1088c3939 - main
thread panicked while panicking. aborting.
[1] 28483 illegal hardware instruction deno example.ts

开启一个子进程同时用管道输出 问题

子进程管道输出代码

const process = Deno.run({
  args:['deno','run','--allow-net', './server.ts'],
  stdout: 'piped'
})
const stdout = process.stdout
const chunk =  new Uint8Array(1024)
await stdout.read(chunk)

console.log(`[process.stdout]:${new TextDecoder().decode(chunk)}`);


setTimeout(() => {
  process.close()
}, 1000*60);

执行代码报错,没找到原因

➜  process deno run --allow-run run.ts         
Compile file:///work/coding/learn/denodemo/src/process/run.ts
error TS2532: Object is possibly 'undefined'.

► file:///work/coding/learn/denodemo/src/process/run.ts:7:7

7 await stdout.read(chunk)

请教代码疑惑🤔

while (true) {
        await env.deferred.promise;
        env.deferred = deferred();
        let queueToProcess = env.queue;
        env.queue = [];
        for (const ctx of queueToProcess) {
            yield ctx;
            // 能解答下这个函数调用用途吗?很迷惑?求教
            serveContext(env, ctx.conn, ctx);
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.